diff --git a/packages/ladle/build-cjs.js b/packages/ladle/build-cjs.js index be8ea848..67509495 100755 --- a/packages/ladle/build-cjs.js +++ b/packages/ladle/build-cjs.js @@ -20,6 +20,38 @@ fs.writeFile( }, ); +const filesWithDirname = [ + "./cjs/lib/cli/vite-base.js", + "./cjs/lib/cli/vite-plugin/generate/get-components-import.js", + "./cjs/lib/cli/vite-plugin/generate/get-config-import.js", + "./cjs/lib/cli/vite-plugin/generate/get-story-imports.js", + "./cjs/lib/cli/vite-plugin/parse/get-entry-data.js", + "./cjs/lib/cli/vite-plugin/generate/get-story-list.js", +]; + +filesWithDirname.forEach((file) => { + const content = fs.readFileSync(file, "utf8"); + fs.writeFile( + file, + content + .replace( + `const __dirname = (0, _path.dirname)((0, _url.fileURLToPath)(import.meta.url));`, + "", + ) + .replace( + `const _dirname = _path.default.dirname((0, _url.fileURLToPath)(import.meta.url));`, + "const _dirname = __dirname", + ) + .replace("_template.default.default", "_template.default") + .replace("_generator.default.default", "_generator.default") + .replace("_traverse.default.default", "_traverse.default"), + (err) => { + if (err) return console.log(err); + console.log(`${file} updated`); + }, + ); +}); + // replacing default config import const getConfig = fs.readFileSync("cjs/lib/app/src/get-config.ts", "utf8"); fs.writeFile( diff --git a/packages/ladle/lib/cli/vite-plugin/ast-to-obj.js b/packages/ladle/lib/cli/vite-plugin/ast-to-obj.js index c1ab1b9d..0b6f51b4 100644 --- a/packages/ladle/lib/cli/vite-plugin/ast-to-obj.js +++ b/packages/ladle/lib/cli/vite-plugin/ast-to-obj.js @@ -2,7 +2,7 @@ // nd-02110114/babel-plugin-object-to-json-parse // https://github.com/nd-02110114/babel-plugin-object-to-json-parse/blob/master/src/utils.ts -import babelTypes from "@babel/types"; +import * as babelTypes from "@babel/types"; const { isArrayExpression, isBooleanLiteral, diff --git a/packages/ladle/lib/cli/vite-plugin/generate/get-story-imports.js b/packages/ladle/lib/cli/vite-plugin/generate/get-story-imports.js index e690a211..c0faa17c 100644 --- a/packages/ladle/lib/cli/vite-plugin/generate/get-story-imports.js +++ b/packages/ladle/lib/cli/vite-plugin/generate/get-story-imports.js @@ -1,6 +1,6 @@ import template from "@babel/template"; import generate from "@babel/generator"; -import t from "@babel/types"; +import * as t from "@babel/types"; import path from "path"; import { fileURLToPath } from "url"; diff --git a/packages/ladle/lib/cli/vite-plugin/generate/get-story-list.js b/packages/ladle/lib/cli/vite-plugin/generate/get-story-list.js index 8f0bb65c..8a426576 100644 --- a/packages/ladle/lib/cli/vite-plugin/generate/get-story-list.js +++ b/packages/ladle/lib/cli/vite-plugin/generate/get-story-list.js @@ -1,7 +1,7 @@ -import t from "@babel/types"; -import { storyDelimiter, storyEncodeDelimiter } from "../naming-utils.js"; +import * as t from "@babel/types"; import generate from "@babel/generator"; import template from "@babel/template"; +import { storyDelimiter, storyEncodeDelimiter } from "../naming-utils.js"; /** * @param entryData {import('../../../shared/types').EntryData} diff --git a/packages/ladle/lib/cli/vite-plugin/get-ast.js b/packages/ladle/lib/cli/vite-plugin/get-ast.js index b4975020..c9808941 100644 --- a/packages/ladle/lib/cli/vite-plugin/get-ast.js +++ b/packages/ladle/lib/cli/vite-plugin/get-ast.js @@ -1,4 +1,4 @@ -import parser from "@babel/parser"; +import * as parser from "@babel/parser"; import { codeFrameColumns } from "@babel/code-frame"; /** diff --git a/packages/ladle/package.json b/packages/ladle/package.json index 047ead06..ad0699b2 100644 --- a/packages/ladle/package.json +++ b/packages/ladle/package.json @@ -40,7 +40,7 @@ "commander": "^8.3.0", "debug": "^4.3.2", "express": "^4.17.1", - "get-port": "^6.0.0", + "get-port": "^5.0.0", "globby": "^11.0.4", "lodash.clonedeep": "^4.5.0", "lodash.merge": "^4.6.2", diff --git a/yarn.lock b/yarn.lock index ef9ce457..e4ce6378 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7895,16 +7895,11 @@ get-pkg-repo@^1.0.0: parse-github-repo-url "^1.3.0" through2 "^2.0.0" -get-port@^5.1.1: +get-port@^5.0.0, get-port@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193" integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ== -get-port@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/get-port/-/get-port-6.0.0.tgz#eeac06c17b9d22c2949d4ce5abcc80753afe9be1" - integrity sha512-qSVkVF6Eq1GdL/cBNiFuP4nUHMF7OEMTqEjC6alR2N90u8BFOoO0PFhNTX2QtAUoGrz8NnrSWj85TZ8YXZ6LOA== - get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"