@modern-js/module-tools 2.48.0 → 2.48.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.
@@ -32,7 +32,6 @@ __export(esbuild_exports, {
32
32
  createCompiler: () => createCompiler
33
33
  });
34
34
  module.exports = __toCommonJS(esbuild_exports);
35
- var import_define_property = require("@swc/helpers/_/_define_property");
36
35
  var import_path = __toESM(require("path"));
37
36
  var import_esbuild = require("esbuild");
38
37
  var tapable = __toESM(require("tapable"));
@@ -231,23 +230,11 @@ class EsbuildCompiler {
231
230
  }
232
231
  }
233
232
  constructor(context2) {
234
- (0, import_define_property._)(this, "instance", void 0);
235
- (0, import_define_property._)(this, "result", void 0);
236
- (0, import_define_property._)(this, "hookList", void 0);
237
- (0, import_define_property._)(this, "reBuildCount", void 0);
238
- (0, import_define_property._)(this, "buildOptions", void 0);
239
- (0, import_define_property._)(this, "context", void 0);
240
- (0, import_define_property._)(this, "config", void 0);
241
- (0, import_define_property._)(this, "hooks", void 0);
242
- (0, import_define_property._)(this, "api", void 0);
243
- (0, import_define_property._)(this, "outputChunk", /* @__PURE__ */ new Map());
244
- (0, import_define_property._)(this, "watchedFiles", /* @__PURE__ */ new Set());
245
- (0, import_define_property._)(this, "css_resolve", void 0);
246
- (0, import_define_property._)(this, "node_resolve", void 0);
247
- (0, import_define_property._)(this, "watcher", void 0);
248
- (0, import_define_property._)(this, "virtualModule", /* @__PURE__ */ new Map());
249
- (0, import_define_property._)(this, "transformContextMap", /* @__PURE__ */ new Map());
250
- (0, import_define_property._)(this, "sourcemapContextMap", /* @__PURE__ */ new Map());
233
+ this.outputChunk = /* @__PURE__ */ new Map();
234
+ this.watchedFiles = /* @__PURE__ */ new Set();
235
+ this.virtualModule = /* @__PURE__ */ new Map();
236
+ this.transformContextMap = /* @__PURE__ */ new Map();
237
+ this.sourcemapContextMap = /* @__PURE__ */ new Map();
251
238
  const { api, config, root } = context2;
252
239
  this.reBuildCount = 0;
253
240
  this.context = context2;
@@ -21,7 +21,6 @@ __export(sourcemap_exports, {
21
21
  SourcemapContext: () => SourcemapContext
22
22
  });
23
23
  module.exports = __toCommonJS(sourcemap_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  var import_utils = require("../../utils");
26
25
  class SourcemapContext {
27
26
  markSourceMapStatus(dirty) {
@@ -67,12 +66,6 @@ class SourcemapContext {
67
66
  return id;
68
67
  }
69
68
  constructor(enableSourceMap) {
70
- (0, import_define_property._)(this, "enableSourceMap", void 0);
71
- (0, import_define_property._)(this, "sourceMapChain", void 0);
72
- (0, import_define_property._)(this, "sourceMapDirty", void 0);
73
- (0, import_define_property._)(this, "cachedInlineSourceMap", void 0);
74
- (0, import_define_property._)(this, "cachedSourceMap", void 0);
75
- (0, import_define_property._)(this, "pluginIdMap", void 0);
76
69
  this.enableSourceMap = enableSourceMap;
77
70
  this.sourceMapChain = [];
78
71
  this.sourceMapDirty = false;
@@ -21,7 +21,6 @@ __export(transform_exports, {
21
21
  TransformContext: () => TransformContext
22
22
  });
23
23
  module.exports = __toCommonJS(transform_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  var import_sourcemap = require("./sourcemap");
26
25
  class TransformContext extends import_sourcemap.SourcemapContext {
27
26
  addTransformResult(pluginId, result) {
@@ -36,7 +35,7 @@ class TransformContext extends import_sourcemap.SourcemapContext {
36
35
  }
37
36
  constructor(...args) {
38
37
  super(...args);
39
- (0, import_define_property._)(this, "cachedTransformResult", /* @__PURE__ */ new Map());
38
+ this.cachedTransformResult = /* @__PURE__ */ new Map();
40
39
  }
41
40
  }
42
41
  // Annotate the CommonJS export names for ESM import in node:
@@ -167,68 +167,72 @@ const redirect = {
167
167
  }
168
168
  return result;
169
169
  }, {});
170
- let matchModule = [];
171
170
  try {
172
171
  const sgNode = import_napi.js.parse(code).root();
173
- const funcPattern = [
174
- `require($MATCH)`,
175
- `import($MATCH)`
176
- ];
177
- const staticPattern = [
178
- `import $VAR from '$MATCH'`,
179
- `import $VAR from "$MATCH"`,
180
- `export {$$$VAR} from '$MATCH'`,
181
- `export {$$$VAR} from "$MATCH"`,
182
- `export * from '$MATCH'`,
183
- `export * from "$MATCH"`,
184
- `export * as $VAR from '$MATCH'`,
185
- `export * as $VAR from "$MATCH"`,
186
- `import '$MATCH'`,
187
- `import "$MATCH"`
188
- ];
189
- const funcMatchModule = funcPattern.map((p) => {
190
- return sgNode.findAll(p);
191
- }).flat().map((node) => {
192
- const matchNode = node.getMatch("MATCH");
193
- return {
194
- name: matchNode.text().slice(1, -1),
195
- start: matchNode.range().start.index + 1,
196
- end: matchNode.range().end.index - 1
197
- };
198
- });
199
- const staticMatchModule = staticPattern.map((p) => sgNode.findAll(p)).flat().map((node) => {
200
- const matchNode = node.getMatch("MATCH");
172
+ const matcher = {
173
+ rule: {
174
+ kind: "string_fragment",
175
+ any: [
176
+ {
177
+ inside: {
178
+ stopBy: "end",
179
+ kind: "import_statement",
180
+ field: "source"
181
+ }
182
+ },
183
+ {
184
+ inside: {
185
+ stopBy: "end",
186
+ kind: "export_statement",
187
+ field: "source"
188
+ }
189
+ },
190
+ {
191
+ inside: {
192
+ kind: "string",
193
+ inside: {
194
+ kind: "arguments",
195
+ inside: {
196
+ kind: "call_expression",
197
+ has: {
198
+ field: "function",
199
+ regex: "^(import|require)$"
200
+ }
201
+ }
202
+ }
203
+ }
204
+ }
205
+ ]
206
+ }
207
+ };
208
+ const matchModule = sgNode.findAll(matcher).map((matchNode) => {
201
209
  return {
202
210
  name: matchNode.text(),
203
211
  start: matchNode.range().start.index,
204
212
  end: matchNode.range().end.index
205
213
  };
206
214
  });
207
- matchModule = [
208
- ...funcMatchModule,
209
- ...staticMatchModule
210
- ];
215
+ if (matchModule.length > 0) {
216
+ const { jsExtension, isModule } = (0, import_utils2.getDefaultOutExtension)({
217
+ format,
218
+ root,
219
+ autoExtension
220
+ });
221
+ const outputPath = (0, import_path.resolve)(outDir, (0, import_path.relative)(sourceDir, id));
222
+ const str = await redirectImport(compiler, code, matchModule, absoluteAlias, id, (0, import_path.dirname)(outputPath), jsExtension, isModule, matchPath);
223
+ return {
224
+ ...args,
225
+ code: str.toString(),
226
+ map: str.generateMap({
227
+ hires: true,
228
+ includeContent: true
229
+ })
230
+ };
231
+ }
211
232
  } catch (e) {
212
233
  import_utils.logger.error("[parse error]", e);
213
234
  }
214
- if (!matchModule.length) {
215
- return args;
216
- }
217
- const { jsExtension, isModule } = (0, import_utils2.getDefaultOutExtension)({
218
- format,
219
- root,
220
- autoExtension
221
- });
222
- const outputPath = (0, import_path.resolve)(outDir, (0, import_path.relative)(sourceDir, id));
223
- const str = await redirectImport(compiler, code, matchModule, absoluteAlias, id, (0, import_path.dirname)(outputPath), jsExtension, isModule, matchPath);
224
- return {
225
- ...args,
226
- code: str.toString(),
227
- map: str.generateMap({
228
- hires: true,
229
- includeContent: true
230
- })
231
- };
235
+ return args;
232
236
  });
233
237
  }
234
238
  };
@@ -31,7 +31,6 @@ __export(lessAliasPlugin_exports, {
31
31
  default: () => LessAliasesPlugin
32
32
  });
33
33
  module.exports = __toCommonJS(lessAliasPlugin_exports);
34
- var import_define_property = require("@swc/helpers/_/_define_property");
35
34
  var import_fs = __toESM(require("fs"));
36
35
  var import_utils = require("./utils");
37
36
  class LessAliasesPlugin {
@@ -51,7 +50,6 @@ class LessAliasesPlugin {
51
50
  }
52
51
  constructor(options) {
53
52
  super();
54
- (0, import_define_property._)(this, "compiler", void 0);
55
53
  this.compiler = options.compiler;
56
54
  this.stdinDir = options.stdinDir;
57
55
  }
@@ -62,8 +60,6 @@ class LessAliasesPlugin {
62
60
  }));
63
61
  }
64
62
  constructor(options) {
65
- (0, import_define_property._)(this, "compiler", void 0);
66
- (0, import_define_property._)(this, "stdinDir", void 0);
67
63
  this.compiler = options.compiler;
68
64
  this.stdinDir = options.stdinDir;
69
65
  }
@@ -126,13 +126,14 @@ const swcTransform = (userTsconfig) => ({
126
126
  });
127
127
  }
128
128
  });
129
+ const JS_REGEX = /\.(?:js|mjs|cjs)$/;
129
130
  const swcRenderChunk = {
130
131
  name: "swc:renderChunk",
131
132
  apply(compiler) {
132
133
  compiler.hooks.renderChunk.tapPromise({
133
134
  name: "swc:renderChunk"
134
135
  }, async (chunk) => {
135
- if (chunk.fileName.endsWith(".js") && chunk.type === "chunk") {
136
+ if (JS_REGEX.test(chunk.fileName) && chunk.type === "chunk") {
136
137
  const { umdModuleName, format } = compiler.config;
137
138
  const name2 = typeof umdModuleName === "function" ? umdModuleName(chunk.fileName) : umdModuleName;
138
139
  const swcCompiler = new import_swc_plugins.Compiler({
package/dist/error.js CHANGED
@@ -26,7 +26,6 @@ __export(error_exports, {
26
26
  padSpaceWith: () => padSpaceWith
27
27
  });
28
28
  module.exports = __toCommonJS(error_exports);
29
- var import_define_property = require("@swc/helpers/_/_define_property");
30
29
  var import_utils = require("@modern-js/utils");
31
30
  const padSpaceWith = (str, targetL, opts = {}) => {
32
31
  const { endStr = "|", style } = opts;
@@ -77,9 +76,6 @@ Detailed Information: `));
77
76
  }
78
77
  constructor(e, opts) {
79
78
  super(e.stack);
80
- (0, import_define_property._)(this, "buildType", void 0);
81
- (0, import_define_property._)(this, "target", void 0);
82
- (0, import_define_property._)(this, "format", void 0);
83
79
  Error.captureStackTrace(this, this.constructor);
84
80
  this.buildType = opts.buildType;
85
81
  this.target = opts.target;
@@ -106,8 +102,6 @@ class InternalDTSError extends Error {
106
102
  }
107
103
  constructor(e, opts) {
108
104
  super(e.message);
109
- (0, import_define_property._)(this, "buildType", void 0);
110
- (0, import_define_property._)(this, "e", void 0);
111
105
  Error.captureStackTrace(this, this.constructor);
112
106
  this.e = e;
113
107
  this.buildType = opts.buildType;
@@ -43,7 +43,7 @@ export interface ITsconfig {
43
43
  } | undefined;
44
44
  include?: string[];
45
45
  exclude?: string[];
46
- extends?: string;
46
+ extends?: string | string[];
47
47
  references?: {
48
48
  path?: string;
49
49
  }[];
@@ -1,5 +1,5 @@
1
1
  import type { ITsconfig, GeneratorDtsConfig, BuildType, TsTarget } from '../types';
2
- export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
2
+ export declare const getProjectTsconfig: (tsconfigPath: string, resolutionContext?: Record<string, boolean>) => Promise<ITsconfig>;
3
3
  export declare function detectTSVersion(appDirectory?: string): Promise<number | undefined>;
4
4
  export declare const getTscBinPath: (appDirectory: string) => Promise<string>;
5
5
  export declare const processDtsFilesAfterTsc: (config: GeneratorDtsConfig) => Promise<void>;
package/dist/utils/dts.js CHANGED
@@ -38,15 +38,41 @@ __export(dts_exports, {
38
38
  module.exports = __toCommonJS(dts_exports);
39
39
  var import_path = require("path");
40
40
  var import_utils = require("@modern-js/utils");
41
+ var import_lodash = require("@modern-js/utils/lodash");
41
42
  var import_magic_string = __toESM(require("magic-string"));
42
43
  var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
43
44
  var import_napi = require("@ast-grep/napi");
44
45
  var import_builder = require("./builder");
45
- const getProjectTsconfig = async (tsconfigPath) => {
46
+ const getProjectTsconfig = async (tsconfigPath, resolutionContext = {}) => {
46
47
  if (!import_utils.fs.existsSync(tsconfigPath)) {
47
48
  return {};
48
49
  }
49
- return import_utils.json5.parse(import_utils.fs.readFileSync(tsconfigPath, "utf-8"));
50
+ const absolutePath = (0, import_path.resolve)(tsconfigPath);
51
+ if (resolutionContext[absolutePath]) {
52
+ return {};
53
+ }
54
+ resolutionContext[absolutePath] = true;
55
+ const tsConfig = await import_utils.json5.parse(import_utils.fs.readFileSync(tsconfigPath, "utf-8"));
56
+ if (!tsConfig.extends) {
57
+ return tsConfig;
58
+ }
59
+ const extendsResolutionTarget = tsConfig.extends instanceof Array ? tsConfig.extends : [
60
+ tsConfig.extends
61
+ ];
62
+ const resolveParentTsConfigPromises = extendsResolutionTarget.map(async (target) => {
63
+ let parentTsconfigPath;
64
+ try {
65
+ parentTsconfigPath = require.resolve(target);
66
+ if (!parentTsconfigPath.endsWith(".json")) {
67
+ parentTsconfigPath = require.resolve(`${target}/tsconfig.json`);
68
+ }
69
+ } catch {
70
+ parentTsconfigPath = (0, import_path.resolve)((0, import_path.dirname)(tsconfigPath), target);
71
+ }
72
+ return await getProjectTsconfig(parentTsconfigPath, resolutionContext);
73
+ });
74
+ const parentTsConfigs = await Promise.all(resolveParentTsConfigPromises);
75
+ return (0, import_lodash.mergeWith)({}, ...parentTsConfigs, tsConfig);
50
76
  };
51
77
  async function detectTSVersion(appDirectory) {
52
78
  const cwd = appDirectory !== null && appDirectory !== void 0 ? appDirectory : process.cwd();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/module-tools",
3
- "version": "2.48.0",
3
+ "version": "2.48.1",
4
4
  "description": "Simple, powerful, high-performance modern npm package development solution.",
5
5
  "keywords": [
6
6
  "modern",
@@ -57,7 +57,7 @@
57
57
  "enhanced-resolve": "5.12.0",
58
58
  "esbuild": "0.19.2",
59
59
  "magic-string": "0.30.5",
60
- "postcss": "8.4.31",
60
+ "postcss": "^8.4.35",
61
61
  "postcss-modules": "4.3.0",
62
62
  "safe-identifier": "0.4.2",
63
63
  "source-map": "0.7.4",
@@ -66,22 +66,22 @@
66
66
  "tapable": "2.2.1",
67
67
  "terser": "5.19.2",
68
68
  "tsconfig-paths-webpack-plugin": "4.1.0",
69
- "@modern-js/core": "2.48.0",
70
- "@modern-js/plugin": "2.48.0",
71
- "@modern-js/plugin-changeset": "2.48.0",
72
- "@modern-js/types": "2.48.0",
73
- "@modern-js/plugin-lint": "2.48.0",
74
- "@modern-js/plugin-i18n": "2.48.0",
75
- "@modern-js/utils": "2.48.0"
69
+ "@modern-js/core": "2.48.1",
70
+ "@modern-js/plugin": "2.48.1",
71
+ "@modern-js/plugin-changeset": "2.48.1",
72
+ "@modern-js/plugin-i18n": "2.48.1",
73
+ "@modern-js/utils": "2.48.1",
74
+ "@modern-js/types": "2.48.1",
75
+ "@modern-js/plugin-lint": "2.48.1"
76
76
  },
77
77
  "devDependencies": {
78
- "@rsbuild/core": "0.4.8",
78
+ "@rsbuild/core": "0.4.15",
79
79
  "@types/convert-source-map": "1.5.2",
80
80
  "@types/node": "^14",
81
81
  "typescript": "^5",
82
- "@modern-js/self": "npm:@modern-js/module-tools@2.48.0",
83
- "@scripts/build": "2.48.0",
84
- "@scripts/vitest-config": "2.48.0"
82
+ "@modern-js/self": "npm:@modern-js/module-tools@2.48.1",
83
+ "@scripts/vitest-config": "2.48.1",
84
+ "@scripts/build": "2.48.1"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "typescript": "^4 || ^5"