Skip to content

Commit

Permalink
fix: cjs version of this package (tajo#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
tajo authored Nov 8, 2021
1 parent 6094707 commit 0c7871f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
32 changes: 32 additions & 0 deletions packages/ladle/build-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/ladle/lib/cli/vite-plugin/ast-to-obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
4 changes: 2 additions & 2 deletions packages/ladle/lib/cli/vite-plugin/generate/get-story-list.js
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 1 addition & 1 deletion packages/ladle/lib/cli/vite-plugin/get-ast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parser from "@babel/parser";
import * as parser from "@babel/parser";
import { codeFrameColumns } from "@babel/code-frame";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ladle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0c7871f

Please sign in to comment.