Skip to content

Commit

Permalink
pref(cli): jiti use sucrase.transform & remove __dirname in the esm f…
Browse files Browse the repository at this point in the history
…ile.
  • Loading branch information
molvqingtai committed May 27, 2023
1 parent ffc5835 commit e1d80f5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
7 changes: 3 additions & 4 deletions packages/rspack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
"dev": "tsc -b -w",
"test": "jest --runInBand"
},
"files": [
"bin",
"dist"
],
"files": ["bin", "dist"],
"homepage": "https://rspack.dev",
"bugs": "https://github.com/web-infra-dev/rspack/issues",
"repository": {
Expand All @@ -37,7 +34,9 @@
"@rspack/core": "workspace:*",
"@rspack/dev-server": "workspace:*",
"colorette": "2.0.19",
"jiti": "^1.18.2",
"semver": "6.3.0",
"sucrase": "^3.32.0",
"webpack-bundle-analyzer": "4.6.1",
"yargs": "17.6.2"
}
Expand Down
15 changes: 12 additions & 3 deletions packages/rspack-cli/src/utils/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import { RspackCLIOptions } from "../types";
import { RspackOptions, MultiRspackOptions } from "@rspack/core";
import findExtFile from "./findExtFile";
import jiti from "jiti";
import { transform } from "sucrase";

const DEFAULT_CONFIG_NAME = "rspack.config" as const;

// Use it to load configuration files from https://github.com/unjs/jiti.
const jitiLoad = (filePath: string) => {
return jiti(__filename, { interopDefault: true })(filePath);
};
const jitiLoad = (() => {
return jiti(__filename, {
interopDefault: true,
cache: true,
transform: options => {
return transform(options.source, {
transforms: ["typescript", "imports"]
});
}
});
})();

export type LoadedRspackConfig =
| undefined
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-cli/tests/build/basic/entry.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import url from "url";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
// import url from "url";
// const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
export default {
context: __dirname,
mode: "development",
Expand Down
5 changes: 0 additions & 5 deletions packages/rspack-cli/tests/build/config/cjs/tsconfig.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/rspack-cli/tests/build/config/esm/rspack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
// import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
// const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
mode: "production",
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-cli/tests/build/config/esm/rspack.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
// import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
// const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
mode: "production",
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-cli/tests/build/config/esm/rspack.config.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
// import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
// const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
mode: "production",
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-cli/tests/build/config/esm/rspack.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
// import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
// const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
mode: "production",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import packageA_deps from "./packageA/index";
import packageB_deps from "./packageB/index";

import path from "node:path";
import { fileURLToPath } from "node:url";
// import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
// const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
mode: "production",
Expand Down

0 comments on commit e1d80f5

Please sign in to comment.