@modern-js/module-tools 2.41.0 → 2.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/build.d.ts +1 -1
  2. package/dist/builder/build.d.ts +7 -7
  3. package/dist/builder/build.js +3 -1
  4. package/dist/builder/clear.d.ts +1 -2
  5. package/dist/builder/clear.js +2 -8
  6. package/dist/builder/copy.d.ts +9 -9
  7. package/dist/builder/dts/index.d.ts +1 -1
  8. package/dist/builder/dts/rollup.d.ts +1 -13
  9. package/dist/builder/dts/tsc.d.ts +1 -1
  10. package/dist/builder/dts/tsc.js +38 -17
  11. package/dist/builder/esbuild/adapter.d.ts +1 -1
  12. package/dist/builder/esbuild/hook.d.ts +1 -1
  13. package/dist/builder/esbuild/index.d.ts +28 -28
  14. package/dist/builder/esbuild/resolve.d.ts +9 -9
  15. package/dist/builder/esbuild/sourcemap.d.ts +14 -14
  16. package/dist/builder/esbuild/transform.d.ts +4 -4
  17. package/dist/builder/esbuild/watch.d.ts +1 -1
  18. package/dist/builder/esbuild/write-file.d.ts +1 -1
  19. package/dist/builder/feature/asset.d.ts +5 -5
  20. package/dist/builder/feature/format-cjs.d.ts +3 -3
  21. package/dist/builder/feature/index.d.ts +1 -1
  22. package/dist/builder/feature/json.d.ts +3 -3
  23. package/dist/builder/feature/redirect.d.ts +3 -3
  24. package/dist/builder/feature/style/index.d.ts +3 -3
  25. package/dist/builder/feature/style/lessAliasPlugin.d.ts +7 -7
  26. package/dist/builder/feature/style/lessRender.d.ts +1 -1
  27. package/dist/builder/feature/style/postcssTransformer.d.ts +3 -3
  28. package/dist/builder/feature/style/postcssUrlPlugin.d.ts +3 -3
  29. package/dist/builder/feature/style/sassRender.d.ts +1 -1
  30. package/dist/builder/feature/style/transformStyle.d.ts +7 -7
  31. package/dist/builder/feature/style/utils.d.ts +3 -3
  32. package/dist/builder/feature/swc.d.ts +5 -5
  33. package/dist/builder/feature/terser.d.ts +3 -3
  34. package/dist/builder/index.d.ts +4 -4
  35. package/dist/builder/index.js +0 -1
  36. package/dist/builder/platform.d.ts +1 -1
  37. package/dist/cli.d.ts +1 -1
  38. package/dist/command.d.ts +1 -1
  39. package/dist/config/defineConfig.d.ts +1 -1
  40. package/dist/config/merge.d.ts +4 -4
  41. package/dist/config/normalize.d.ts +3 -3
  42. package/dist/config/transformLegacyConfig.d.ts +1 -1
  43. package/dist/config/valid.d.ts +1 -1
  44. package/dist/constants/build.d.ts +1 -1
  45. package/dist/constants/color.d.ts +1 -1
  46. package/dist/constants/dts.d.ts +0 -1
  47. package/dist/constants/dts.js +0 -3
  48. package/dist/constants/file.d.ts +1 -1
  49. package/dist/constants/legacy-preset.d.ts +11 -11
  50. package/dist/constants/loader.d.ts +1 -1
  51. package/dist/constants/log.d.ts +1 -1
  52. package/dist/constants/preset.d.ts +5 -5
  53. package/dist/debug.d.ts +1 -1
  54. package/dist/dev.d.ts +1 -1
  55. package/dist/error.d.ts +19 -19
  56. package/dist/hooks/build.d.ts +16 -16
  57. package/dist/hooks/dev.d.ts +11 -11
  58. package/dist/hooks/index.d.ts +29 -29
  59. package/dist/hooks/misc.d.ts +11 -11
  60. package/dist/index.d.ts +1 -1
  61. package/dist/locale/en.d.ts +40 -40
  62. package/dist/locale/index.d.ts +79 -79
  63. package/dist/locale/zh.d.ts +40 -40
  64. package/dist/plugins.d.ts +1 -1
  65. package/dist/types/color.d.ts +1 -1
  66. package/dist/types/command.d.ts +9 -9
  67. package/dist/types/config/copy.d.ts +10 -10
  68. package/dist/types/config/dev.d.ts +4 -4
  69. package/dist/types/config/index.d.ts +106 -106
  70. package/dist/types/config/style.d.ts +37 -37
  71. package/dist/types/context.d.ts +4 -4
  72. package/dist/types/dts.d.ts +39 -38
  73. package/dist/types/esbuild.d.ts +77 -77
  74. package/dist/types/hooks.d.ts +14 -14
  75. package/dist/types/index.d.ts +7 -7
  76. package/dist/types/legacyConfig/index.d.ts +8 -8
  77. package/dist/types/legacyConfig/output.d.ts +44 -44
  78. package/dist/types/legacyConfig/source.d.ts +10 -10
  79. package/dist/types/legacyConfig/tools.d.ts +39 -39
  80. package/dist/utils/assert.d.ts +1 -1
  81. package/dist/utils/builder.d.ts +9 -9
  82. package/dist/utils/common.d.ts +1 -1
  83. package/dist/utils/dts.d.ts +4 -34
  84. package/dist/utils/dts.js +71 -93
  85. package/dist/utils/hash.d.ts +1 -1
  86. package/dist/utils/index.d.ts +1 -2
  87. package/dist/utils/index.js +0 -2
  88. package/dist/utils/input.d.ts +5 -8
  89. package/dist/utils/log.d.ts +1 -1
  90. package/dist/utils/map.d.ts +5 -5
  91. package/dist/utils/onExit.d.ts +1 -1
  92. package/dist/utils/outExtension.d.ts +6 -6
  93. package/dist/utils/print.d.ts +3 -3
  94. package/dist/utils/style.d.ts +7 -7
  95. package/package.json +14 -20
  96. package/dist/utils/tspath.d.ts +0 -15
  97. package/dist/utils/tspath.js +0 -114
package/dist/utils/dts.js CHANGED
@@ -28,69 +28,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var dts_exports = {};
30
30
  __export(dts_exports, {
31
- addBannerAndFooter: () => addBannerAndFooter,
32
- generateDtsInfo: () => generateDtsInfo,
33
31
  getProjectTsconfig: () => getProjectTsconfig,
34
32
  getTscBinPath: () => getTscBinPath,
35
33
  printOrThrowDtsErrors: () => printOrThrowDtsErrors,
36
- resolveAlias: () => resolveAlias,
37
- tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022,
38
- writeDtsFiles: () => writeDtsFiles
34
+ processDtsFilesAfterTsc: () => processDtsFilesAfterTsc,
35
+ tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022
39
36
  });
40
37
  module.exports = __toCommonJS(dts_exports);
41
38
  var import_path = require("path");
42
39
  var import_utils = require("@modern-js/utils");
43
40
  var import_magic_string = __toESM(require("magic-string"));
41
+ var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
42
+ var import_napi = require("@ast-grep/napi");
43
+ var import_builder = require("./builder");
44
44
  const getProjectTsconfig = async (tsconfigPath) => {
45
45
  if (!import_utils.fs.existsSync(tsconfigPath)) {
46
46
  return {};
47
47
  }
48
48
  return import_utils.json5.parse(import_utils.fs.readFileSync(tsconfigPath, "utf-8"));
49
49
  };
50
- const generateDtsInfo = async (config) => {
51
- var _userTsconfig_references;
52
- const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;
53
- const userTsconfig = await getProjectTsconfig(tsconfigPath);
54
- const { dtsTempDirectory } = await Promise.resolve().then(() => __toESM(require("../constants/dts")));
55
- const tempDistAbsRootPath = (0, import_path.join)(appDirectory, `${dtsTempDirectory}/${(0, import_utils.nanoid)()}`);
56
- const tempDistAbsOurDir = (0, import_path.join)(tempDistAbsRootPath, (0, import_path.relative)(appDirectory, absSourceDir));
57
- const tempTsconfigPath = (0, import_path.join)(tempDistAbsRootPath, (0, import_path.basename)(tsconfigPath));
58
- import_utils.fs.ensureFileSync(tempTsconfigPath);
59
- const extendsPath = (0, import_path.join)((0, import_path.relative)((0, import_path.dirname)(tempTsconfigPath), (0, import_path.dirname)(tsconfigPath)), (0, import_path.basename)(tempTsconfigPath));
60
- const references = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_references = userTsconfig.references) === null || _userTsconfig_references === void 0 ? void 0 : _userTsconfig_references.map((reference) => {
61
- const { path } = reference;
62
- if (path) {
63
- const userTsconfigDir = (0, import_path.dirname)(tsconfigPath);
64
- const generatedTsconfigDir = (0, import_path.dirname)(tempTsconfigPath);
65
- return {
66
- path: (0, import_path.isAbsolute)(path) ? path : (0, import_path.relative)(generatedTsconfigDir, (0, import_path.resolve)(userTsconfigDir, path))
67
- };
68
- }
69
- return reference;
70
- });
71
- const resetConfig = {
72
- extends: extendsPath,
73
- compilerOptions: {
74
- // Ensure that .d.ts files are created by tsc, but not .js files
75
- declaration: true,
76
- emitDeclarationOnly: true,
77
- // when `outDir` is './dist', `declarationDir` is `./types`
78
- // tsc will emit:
79
- // - ./dist/index.js
80
- // - ./types/index.d.ts
81
- // we only want to emit declarations
82
- declarationDir: tempDistAbsOurDir
83
- },
84
- references
85
- };
86
- import_utils.fs.writeJSONSync(tempTsconfigPath, resetConfig);
87
- return {
88
- userTsconfig,
89
- tempTsconfigPath,
90
- tempDistAbsRootPath,
91
- tempDistAbsSrcPath: tempDistAbsOurDir
92
- };
93
- };
94
50
  const getTscBinPath = async (appDirectory) => {
95
51
  const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => __toESM(require("../../compiled/find-up")));
96
52
  const tscBinFile = await findUp(async (directory) => {
@@ -108,58 +64,83 @@ const getTscBinPath = async (appDirectory) => {
108
64
  }
109
65
  return tscBinFile;
110
66
  };
111
- const resolveAlias = async (config, options, watchFilenames = []) => {
112
- var _userTsconfig_compilerOptions;
113
- const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;
114
- const { transformDtsAlias } = await Promise.resolve().then(() => __toESM(require("./tspath")));
115
- const dtsDistPath = `${(0, import_utils.slash)(tempDistAbsSrcPath)}/**/*.d.ts`;
116
- const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : import_utils.globby.sync(dtsDistPath, {
117
- absolute: true
118
- });
119
- var _userTsconfig_compilerOptions_paths;
120
- const result = transformDtsAlias({
121
- filenames: dtsFilenames,
122
- baseUrl: tempDistAbsRootPath,
123
- paths: (_userTsconfig_compilerOptions_paths = (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.paths) !== null && _userTsconfig_compilerOptions_paths !== void 0 ? _userTsconfig_compilerOptions_paths : {}
67
+ const processDtsFilesAfterTsc = async (config) => {
68
+ const { distPath, tsconfigPath, userTsconfig, dtsExtension, banner, footer } = config;
69
+ const dtsFilesPath = await (0, import_utils.globby)("**/*.d.ts", {
70
+ absolute: true,
71
+ cwd: distPath
124
72
  });
125
- return result;
126
- };
127
- const writeDtsFiles = async (config, options, result) => {
128
- const { distPath, dtsExtension } = config;
129
- const { tempDistAbsSrcPath } = options;
130
- await Promise.all(result.map(({ path, content }) => {
131
- const relativePath = (0, import_path.relative)(tempDistAbsSrcPath, path);
132
- const filepath = (0, import_path.join)(
133
- distPath,
73
+ const result = (0, import_tsconfig_paths.loadConfig)(tsconfigPath);
74
+ if (result.resultType === "failed") {
75
+ import_utils.logger.error(result.message);
76
+ return;
77
+ }
78
+ const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
79
+ const matchPath = (0, import_tsconfig_paths.createMatchPath)(absoluteBaseUrl, paths, mainFields, addMatchAll);
80
+ const Pattern = [
81
+ `import $VAR from '$MATCH'`,
82
+ `import $VAR from "$MATCH"`,
83
+ `export {$$$VAR} from '$MATCH'`,
84
+ `export {$$$VAR} from "$MATCH"`,
85
+ `export * from '$MATCH'`,
86
+ `export * from "$MATCH"`,
87
+ `export * as $VAR from '$MATCH'`,
88
+ `export * as $VAR from "$MATCH"`,
89
+ `import('$MATCH')`,
90
+ `import("$MATCH")`
91
+ ];
92
+ await Promise.all(dtsFilesPath.map((filePath) => {
93
+ var _userTsconfig_compilerOptions;
94
+ const code = import_utils.fs.readFileSync(filePath, "utf8");
95
+ let matchModule = [];
96
+ try {
97
+ const sgNode = import_napi.ts.parse(code).root();
98
+ matchModule = Pattern.map((p) => sgNode.findAll(p)).flat().map((node) => {
99
+ const matchNode = node.getMatch("MATCH");
100
+ return {
101
+ name: matchNode.text(),
102
+ start: matchNode.range().start.index,
103
+ end: matchNode.range().end.index
104
+ };
105
+ });
106
+ } catch (e) {
107
+ import_utils.logger.error("[parse error]", e);
108
+ }
109
+ const str = new import_magic_string.default(code);
110
+ const originalFilePath = (0, import_path.resolve)(absoluteBaseUrl, (userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.rootDir) || "src", (0, import_path.relative)(distPath, filePath));
111
+ matchModule.forEach((module2) => {
112
+ if (!module2.name) {
113
+ return;
114
+ }
115
+ const { start, end, name } = module2;
116
+ const absoluteImportPath = matchPath(name);
117
+ if (absoluteImportPath) {
118
+ const relativePath = (0, import_path.relative)((0, import_path.dirname)(originalFilePath), absoluteImportPath);
119
+ const relativeImportPath = (0, import_builder.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
120
+ str.overwrite(start, end, relativeImportPath);
121
+ }
122
+ });
123
+ banner && str.prepend(`${banner}
124
+ `);
125
+ footer && str.append(`
126
+ ${footer}
127
+ `);
128
+ const content = str.toString();
129
+ const finalPath = (
134
130
  // We confirm that users will not mix ts and c(m)ts files in their projects.
135
131
  // If a mix is required, please configure separate buildConfig to handle different inputs.
136
132
  // So we don't replace .d.(c|m)ts that generated by tsc directly, this can confirm that
137
133
  // users can use c(m)ts directly rather than enable autoExtension, in this condition,
138
134
  // users need to set esbuild out-extensions like { '.js': '.mjs' }
139
- relativePath.replace(/\.d\.ts/, dtsExtension)
135
+ filePath.replace(/\.d\.ts/, dtsExtension)
140
136
  );
141
- import_utils.fs.ensureFileSync(filepath);
142
137
  return import_utils.fs.writeFile(
143
138
  // only replace .d.ts, if tsc generate .d.m(c)ts, keep.
144
- filepath,
139
+ finalPath,
145
140
  content
146
141
  );
147
142
  }));
148
143
  };
149
- const addBannerAndFooter = (result, banner, footer) => {
150
- return result.map(({ path, content }) => {
151
- const ms = new import_magic_string.default(content);
152
- banner && ms.prepend(`${banner}
153
- `);
154
- footer && ms.append(`
155
- ${footer}
156
- `);
157
- return {
158
- path,
159
- content: ms.toString()
160
- };
161
- });
162
- };
163
144
  const printOrThrowDtsErrors = async (error, options) => {
164
145
  const { InternalDTSError } = await Promise.resolve().then(() => __toESM(require("../error")));
165
146
  const local = await Promise.resolve().then(() => __toESM(require("../locale")));
@@ -180,12 +161,9 @@ const printOrThrowDtsErrors = async (error, options) => {
180
161
  const tsTargetAtOrAboveES2022 = (target) => target === "es2022" || target === "esnext";
181
162
  // Annotate the CommonJS export names for ESM import in node:
182
163
  0 && (module.exports = {
183
- addBannerAndFooter,
184
- generateDtsInfo,
185
164
  getProjectTsconfig,
186
165
  getTscBinPath,
187
166
  printOrThrowDtsErrors,
188
- resolveAlias,
189
- tsTargetAtOrAboveES2022,
190
- writeDtsFiles
167
+ processDtsFilesAfterTsc,
168
+ tsTargetAtOrAboveES2022
191
169
  });
@@ -1,2 +1,2 @@
1
1
  /// <reference types="node" />
2
- export declare function getHash(content: Buffer | string, encoding: any, type?: string): string;
2
+ export declare function getHash(content: Buffer | string, encoding: any, type?: string): string;
@@ -8,5 +8,4 @@ export * from './log';
8
8
  export * from './map';
9
9
  export * from './print';
10
10
  export * from './style';
11
- export * from './tspath';
12
- export * from './outExtension';
11
+ export * from './outExtension';
@@ -25,7 +25,6 @@ __reExport(utils_exports, require("./log"), module.exports);
25
25
  __reExport(utils_exports, require("./map"), module.exports);
26
26
  __reExport(utils_exports, require("./print"), module.exports);
27
27
  __reExport(utils_exports, require("./style"), module.exports);
28
- __reExport(utils_exports, require("./tspath"), module.exports);
29
28
  __reExport(utils_exports, require("./outExtension"), module.exports);
30
29
  // Annotate the CommonJS export names for ESM import in node:
31
30
  0 && (module.exports = {
@@ -39,6 +38,5 @@ __reExport(utils_exports, require("./outExtension"), module.exports);
39
38
  ...require("./map"),
40
39
  ...require("./print"),
41
40
  ...require("./style"),
42
- ...require("./tspath"),
43
41
  ...require("./outExtension")
44
42
  });
@@ -1,11 +1,8 @@
1
1
  import { Input } from '../types';
2
- export declare const getDefaultIndexEntry: ({
3
- isTsProject,
4
- appDirectory
5
- }: {
6
- isTsProject: boolean;
7
- appDirectory: string;
2
+ export declare const getDefaultIndexEntry: ({ isTsProject, appDirectory, }: {
3
+ isTsProject: boolean;
4
+ appDirectory: string;
8
5
  }) => Promise<string[]>;
9
6
  export declare const normalizeInput: (input: Input, appDirectory: string, enableSvgr: boolean) => Promise<string[] | {
10
- [name: string]: string;
11
- }>;
7
+ [name: string]: string;
8
+ }>;
@@ -1 +1 @@
1
- export declare const withLogTitle: (titleText: string, message: string) => string;
1
+ export declare const withLogTitle: (titleText: string, message: string) => string;
@@ -1,13 +1,13 @@
1
1
  import { RawSourceMap } from '@ampproject/remapping/dist/types/types';
2
2
  import type { SourceMap } from '../types';
3
3
  interface Options {
4
- needSourceMap: boolean;
4
+ needSourceMap: boolean;
5
5
  }
6
6
  export declare function normalizeSourceMap(map: string | RawSourceMap | undefined, opts?: Options): SourceMap | undefined;
7
7
  export type MergeMapResult = {
8
- toString: () => string;
9
- toMap: () => SourceMap;
10
- toComment: () => string;
8
+ toString: () => string;
9
+ toMap: () => SourceMap;
10
+ toComment: () => string;
11
11
  };
12
12
  export declare function mergeMaps(mapList: SourceMap[]): MergeMapResult;
13
- export {};
13
+ export {};
@@ -1 +1 @@
1
- export declare const addExitListener: (fn: () => Promise<void>) => Promise<void>;
1
+ export declare const addExitListener: (fn: () => Promise<void>) => Promise<void>;
@@ -1,9 +1,9 @@
1
1
  import type { Format } from '../types';
2
2
  export declare const getDefaultOutExtension: (options: {
3
- format: Format;
4
- root: string;
5
- autoExtension: boolean;
3
+ format: Format;
4
+ root: string;
5
+ autoExtension: boolean;
6
6
  }) => {
7
- jsExtension: string;
8
- dtsExtension: string;
9
- };
7
+ jsExtension: string;
8
+ dtsExtension: string;
9
+ };
@@ -1,8 +1,8 @@
1
1
  import type { RollupOutput } from '../../compiled/rollup/types/rollup';
2
2
  import { Chunk } from '../types';
3
3
  type Files = {
4
- name: string;
5
- size: number;
4
+ name: string;
5
+ size: number;
6
6
  };
7
7
  export declare const bundleFiles: Files[];
8
8
  export declare const bundlelessFiles: Files[];
@@ -11,4 +11,4 @@ export declare const addRollupChunk: (rollupOutput: RollupOutput, appDirectory:
11
11
  export declare const addDtsFiles: (distDir: string, appDirectory: string) => Promise<void>;
12
12
  export declare const printFileSize: () => void;
13
13
  export declare const printSucceed: (totalDuration: number) => void;
14
- export {};
14
+ export {};
@@ -2,12 +2,12 @@ import type { PartialBaseBuildConfig, PostcssOptions, LessOptions, SassOptions }
2
2
  export declare const getLessConfig: (config: PartialBaseBuildConfig) => Promise<LessOptions>;
3
3
  export declare const getSassConfig: (config: PartialBaseBuildConfig) => Promise<SassOptions>;
4
4
  export declare const getPostcssConfig: (config: PartialBaseBuildConfig) => Promise<PostcssOptions & {
5
- $$tools?: string | undefined;
5
+ $$tools?: string | undefined;
6
6
  }>;
7
7
  export declare const getStyleConfig: (config: PartialBaseBuildConfig) => Promise<{
8
- less: LessOptions;
9
- sass: SassOptions;
10
- postcss: PostcssOptions & {
11
- $$tools?: string | undefined;
12
- };
13
- }>;
8
+ less: LessOptions;
9
+ sass: SassOptions;
10
+ postcss: PostcssOptions & {
11
+ $$tools?: string | undefined;
12
+ };
13
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/module-tools",
3
- "version": "2.41.0",
3
+ "version": "2.42.1",
4
4
  "description": "Simple, powerful, high-performance modern npm package development solution.",
5
5
  "keywords": [
6
6
  "modern",
@@ -48,10 +48,6 @@
48
48
  "dependencies": {
49
49
  "@ampproject/remapping": "1.0.2",
50
50
  "@ast-grep/napi": "0.12.0",
51
- "@babel/generator": "^7.22.15",
52
- "@babel/parser": "^7.22.15",
53
- "@babel/traverse": "^7.23.2",
54
- "@babel/types": "^7.22.15",
55
51
  "@modern-js/swc-plugins": "0.6.5",
56
52
  "@rollup/pluginutils": "4.1.1",
57
53
  "@svgr/core": "8.0.0",
@@ -71,26 +67,24 @@
71
67
  "tapable": "2.2.1",
72
68
  "terser": "5.19.2",
73
69
  "tsconfig-paths-webpack-plugin": "4.1.0",
74
- "@modern-js/new-action": "2.41.0",
75
- "@modern-js/core": "2.41.0",
76
- "@modern-js/plugin-changeset": "2.41.0",
77
- "@modern-js/plugin": "2.41.0",
78
- "@modern-js/plugin-i18n": "2.41.0",
79
- "@modern-js/plugin-lint": "2.41.0",
80
- "@modern-js/types": "2.41.0",
81
- "@modern-js/utils": "2.41.0",
82
- "@modern-js/upgrade": "2.41.0"
70
+ "@modern-js/core": "2.42.1",
71
+ "@modern-js/new-action": "2.42.1",
72
+ "@modern-js/plugin": "2.42.1",
73
+ "@modern-js/plugin-i18n": "2.42.1",
74
+ "@modern-js/plugin-changeset": "2.42.1",
75
+ "@modern-js/types": "2.42.1",
76
+ "@modern-js/upgrade": "2.42.1",
77
+ "@modern-js/utils": "2.42.1",
78
+ "@modern-js/plugin-lint": "2.42.1"
83
79
  },
84
80
  "devDependencies": {
85
- "@types/babel__generator": "7.6.4",
86
- "@types/babel__traverse": "7.18.5",
87
81
  "@types/convert-source-map": "1.5.2",
88
82
  "@types/node": "^14",
89
83
  "typescript": "^5",
90
- "@modern-js/builder-webpack-provider": "2.41.0",
91
- "@modern-js/self": "npm:@modern-js/module-tools@2.41.0",
92
- "@scripts/vitest-config": "2.41.0",
93
- "@scripts/build": "2.41.0"
84
+ "@modern-js/self": "npm:@modern-js/module-tools@2.42.1",
85
+ "@modern-js/builder-webpack-provider": "2.42.1",
86
+ "@scripts/build": "2.42.1",
87
+ "@scripts/vitest-config": "2.42.1"
94
88
  },
95
89
  "peerDependencies": {
96
90
  "typescript": "^4 || ^5"
@@ -1,15 +0,0 @@
1
- export interface TransformOption {
2
- filename: string;
3
- baseUrl: string;
4
- paths: Record<string, string[] | string>;
5
- }
6
- interface TransformDtsAliasOption {
7
- filenames?: string[];
8
- baseUrl: string;
9
- paths: Record<string, string[] | string>;
10
- }
11
- export declare const transformDtsAlias: (option: TransformDtsAliasOption) => {
12
- path: string;
13
- content: string;
14
- }[];
15
- export {};
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var tspath_exports = {};
30
- __export(tspath_exports, {
31
- transformDtsAlias: () => transformDtsAlias
32
- });
33
- module.exports = __toCommonJS(tspath_exports);
34
- var path = __toESM(require("path"));
35
- var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
36
- var import_utils = require("@modern-js/utils");
37
- var parser = __toESM(require("@babel/parser"));
38
- var import_generator = __toESM(require("@babel/generator"));
39
- var t = __toESM(require("@babel/types"));
40
- var import_traverse = __toESM(require("@babel/traverse"));
41
- var import_file = require("../constants/file");
42
- function mapPathString(nodePath, { filename, baseUrl, paths }) {
43
- if (!t.isStringLiteral(nodePath)) {
44
- return;
45
- }
46
- const sourcePath = nodePath.node.value;
47
- const currentFile = filename;
48
- const matchPath = (0, import_tsconfig_paths.createMatchPath)(baseUrl, paths, [
49
- "index"
50
- ]);
51
- const result = matchPath(sourcePath, (packageJsonPath) => {
52
- if (!import_utils.fs.existsSync(packageJsonPath)) {
53
- return void 0;
54
- }
55
- return import_utils.fs.readJSONSync(packageJsonPath);
56
- }, (filePath) => import_utils.fs.existsSync(filePath), import_file.dtsAliasExts);
57
- if (result) {
58
- const relativePath = path.relative(path.dirname(currentFile), path.dirname(result));
59
- const fileName = path.basename(result);
60
- const filePath = path.normalize(`${relativePath.length === 0 ? "." : relativePath}/${fileName}`);
61
- const replaceString = filePath.startsWith(".") ? filePath : `./${filePath}`;
62
- nodePath.replaceWith(t.stringLiteral(replaceString));
63
- }
64
- }
65
- const transformImport = (option) => (nodePath) => {
66
- mapPathString(nodePath.get("source"), option);
67
- };
68
- const transformExport = (option) => (nodePath) => {
69
- mapPathString(nodePath.get("source"), option);
70
- };
71
- const transformSingleFileAlias = ({ filename, baseUrl, paths }) => {
72
- const sourceCode = import_utils.fs.readFileSync(filename, "utf-8");
73
- const ast = parser.parse(sourceCode, {
74
- sourceType: "module",
75
- errorRecovery: true,
76
- plugins: [
77
- "typescript"
78
- ]
79
- });
80
- (0, import_traverse.default)(ast, {
81
- // d.ts file content not have callExpression which can be parsed;
82
- // CallExpression: transformCall({ filename, baseUrl, paths }) as any,
83
- ImportDeclaration: transformImport({
84
- filename,
85
- baseUrl,
86
- paths
87
- }),
88
- ExportDeclaration: transformExport({
89
- filename,
90
- baseUrl,
91
- paths
92
- })
93
- });
94
- return (0, import_generator.default)(ast).code;
95
- };
96
- const transformDtsAlias = (option) => {
97
- const { filenames = [], baseUrl, paths } = option;
98
- const transformResult = [];
99
- for (const filename of filenames) {
100
- transformResult.push({
101
- path: filename,
102
- content: transformSingleFileAlias({
103
- filename,
104
- baseUrl,
105
- paths
106
- })
107
- });
108
- }
109
- return transformResult;
110
- };
111
- // Annotate the CommonJS export names for ESM import in node:
112
- 0 && (module.exports = {
113
- transformDtsAlias
114
- });