@modern-js/module-tools 2.42.2 → 2.43.0

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.
@@ -21,9 +21,11 @@ __export(clear_exports, {
21
21
  clearBuildConfigPaths: () => clearBuildConfigPaths
22
22
  });
23
23
  module.exports = __toCommonJS(clear_exports);
24
+ var import_path = require("path");
24
25
  var import_utils = require("@modern-js/utils");
25
26
  var import_locale = require("../locale");
26
27
  var import_utils2 = require("../utils");
28
+ var import_debug = require("../debug");
27
29
  const clearBuildConfigPaths = async (configs, projectAbsRootPath) => {
28
30
  for (const config of configs) {
29
31
  if (projectAbsRootPath === config.outDir) {
@@ -31,20 +33,25 @@ const clearBuildConfigPaths = async (configs, projectAbsRootPath) => {
31
33
  } else {
32
34
  await import_utils.fs.remove(config.outDir);
33
35
  }
34
- if (config.buildType === "bundleless" && config.dts && // keep it same as https://github.com/web-infra-dev/modern.js/blob/main/packages/solutions/module-tools/src/builder/build.ts#L37
35
- await import_utils.fs.pathExists(config.tsconfig)) {
36
- const tscBinFile = await (0, import_utils2.getTscBinPath)(projectAbsRootPath);
37
- const childProgress = (0, import_utils.execa)(tscBinFile, [
38
- "--build",
39
- "--clean"
40
- ], {
41
- stdio: "pipe",
42
- cwd: projectAbsRootPath
43
- });
44
- try {
45
- await childProgress;
46
- } catch (e) {
47
- import_utils.logger.error(e);
36
+ if (config.buildType === "bundleless" && config.dts) {
37
+ const { compilerOptions } = await (0, import_utils2.getProjectTsconfig)(config.tsconfig);
38
+ const { composite, incremental, rootDir, tsBuildInfoFile = ".tsbuildinfo" } = compilerOptions || {};
39
+ if (!composite && !incremental) {
40
+ return;
41
+ }
42
+ const outDir = config.dts.distPath;
43
+ const tsconfigDir = (0, import_path.dirname)(config.tsconfig);
44
+ let tsbuildInfoFilePath = `${(0, import_path.basename)(config.tsconfig, ".json")}${tsBuildInfoFile}`;
45
+ if (rootDir) {
46
+ tsbuildInfoFilePath = (0, import_path.resolve)(outDir, (0, import_path.relative)((0, import_path.resolve)(tsconfigDir, rootDir), tsconfigDir), tsbuildInfoFilePath);
47
+ } else {
48
+ tsbuildInfoFilePath = (0, import_path.resolve)(outDir, tsbuildInfoFilePath);
49
+ }
50
+ (0, import_debug.debug)("clear tsbuildinfo");
51
+ if (await import_utils.fs.pathExists(tsbuildInfoFilePath)) {
52
+ await import_utils.fs.remove(tsbuildInfoFilePath);
53
+ } else {
54
+ (0, import_debug.debug)(`${tsbuildInfoFilePath} doesn't exist`);
48
55
  }
49
56
  }
50
57
  }
@@ -242,7 +242,7 @@ const adapterPlugin = (compiler) => {
242
242
  if (!item) {
243
243
  continue;
244
244
  }
245
- if (absPath.endsWith(".js")) {
245
+ if ((0, import_utils2.isJsExt)(absPath)) {
246
246
  compiler.emitAsset(absPath, {
247
247
  type: "chunk",
248
248
  contents: item.text,
@@ -34,8 +34,7 @@ module.exports = __toCommonJS(lessAliasPlugin_exports);
34
34
  var import_define_property = require("@swc/helpers/_/_define_property");
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_utils = require("./utils");
37
- var LessAliasesPlugin;
38
- LessAliasesPlugin = class LessAliasesPlugin2 {
37
+ class LessAliasesPlugin {
39
38
  install(less, pluginManager) {
40
39
  const getResolve = (filename, currentDirectory) => {
41
40
  return this.compiler.css_resolve(filename, currentDirectory || this.stdinDir);
@@ -68,4 +67,4 @@ LessAliasesPlugin = class LessAliasesPlugin2 {
68
67
  this.compiler = options.compiler;
69
68
  this.stdinDir = options.stdinDir;
70
69
  }
71
- };
70
+ }
@@ -33,8 +33,11 @@ const postcssUrlPlugin = (options) => {
33
33
  postcssPlugin: "postcss-url",
34
34
  async Declaration(decl) {
35
35
  const isProcessed = decl[Processed];
36
+ if (isProcessed) {
37
+ return;
38
+ }
36
39
  decl.value = await (0, import_utils.rewriteCssUrls)(decl.value, false, async (URL) => {
37
- if (URL && !HTTP_PATTERNS.test(URL) && !HASH_PATTERNS.test(URL) && !DATAURL_PATTERNS.test(URL) && !isProcessed) {
40
+ if (URL && !HTTP_PATTERNS.test(URL) && !HASH_PATTERNS.test(URL) && !DATAURL_PATTERNS.test(URL)) {
38
41
  let filePath = URL;
39
42
  const { outDir, sourceDir, buildType } = options.compilation.config;
40
43
  const { css_resolve } = options.compilation;
@@ -94,8 +94,12 @@ async function rebaseUrls(filepath, rootDir, resolver) {
94
94
  };
95
95
  }
96
96
  }
97
- function rewriteCssUrls(css, type, replacer) {
98
- return asyncReplace(css, cssUrlRE, async (match) => {
97
+ async function rewriteCssUrls(css, type, replacer) {
98
+ let match;
99
+ let remaining = css;
100
+ let rewritten = "";
101
+ while (match = cssUrlRE.exec(remaining)) {
102
+ rewritten += remaining.slice(0, match.index);
99
103
  const matched = match[0];
100
104
  let rawUrl = match[1];
101
105
  let wrap = "";
@@ -104,19 +108,8 @@ function rewriteCssUrls(css, type, replacer) {
104
108
  wrap = first;
105
109
  rawUrl = rawUrl.slice(1, -1);
106
110
  }
107
- if (type === "less" && rawUrl.startsWith("@") || (type === "sass" || type === "scss") && rawUrl.startsWith("$") || isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl.startsWith("#")) {
108
- return matched;
109
- }
110
- return `url(${wrap}${(0, import_utils.normalizeSlashes)(await replacer(rawUrl))}${wrap})`;
111
- });
112
- }
113
- async function asyncReplace(input, re, replacer) {
114
- let match;
115
- let remaining = input;
116
- let rewritten = "";
117
- while (match = re.exec(remaining)) {
118
- rewritten += remaining.slice(0, match.index);
119
- rewritten += await replacer(match);
111
+ const result = type === "less" && rawUrl.startsWith("@") || (type === "sass" || type === "scss") && rawUrl.startsWith("$") || isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl.startsWith("#") ? matched : `url(${wrap}${(0, import_utils.normalizeSlashes)(await replacer(rawUrl))}${wrap})`;
112
+ rewritten += result;
120
113
  remaining = remaining.slice(match.index + match[0].length);
121
114
  }
122
115
  rewritten += remaining;
@@ -36,6 +36,9 @@ export interface ITsconfig {
36
36
  paths?: Record<string, string[]>;
37
37
  target?: TsTarget;
38
38
  useDefineForClassFields?: boolean;
39
+ composite?: boolean;
40
+ incremental?: boolean;
41
+ tsBuildInfoFile?: string;
39
42
  } | undefined;
40
43
  include?: string[];
41
44
  exclude?: string[];
package/dist/utils/dts.js CHANGED
@@ -144,12 +144,23 @@ ${footer}
144
144
  // users need to set esbuild out-extensions like { '.js': '.mjs' }
145
145
  filePath.replace(/\.d\.ts/, dtsExtension)
146
146
  );
147
- return import_utils.fs.writeFile(
148
- // only replace .d.ts, if tsc generate .d.m(c)ts, keep.
149
- finalPath,
150
- content
151
- );
152
- }));
147
+ const writeTask = () => {
148
+ return import_utils.fs.writeFile(
149
+ // only replace .d.ts, if tsc generate .d.m(c)ts, keep.
150
+ finalPath,
151
+ content
152
+ );
153
+ };
154
+ const removeTask = () => {
155
+ return import_utils.fs.remove(filePath);
156
+ };
157
+ return dtsExtension === ".d.ts" ? [
158
+ writeTask()
159
+ ] : [
160
+ writeTask(),
161
+ removeTask()
162
+ ];
163
+ }).flat());
153
164
  };
154
165
  const printOrThrowDtsErrors = async (error, options) => {
155
166
  const { InternalDTSError } = await Promise.resolve().then(() => __toESM(require("../error")));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/module-tools",
3
- "version": "2.42.2",
3
+ "version": "2.43.0",
4
4
  "description": "Simple, powerful, high-performance modern npm package development solution.",
5
5
  "keywords": [
6
6
  "modern",
@@ -48,7 +48,7 @@
48
48
  "dependencies": {
49
49
  "@ampproject/remapping": "^2.2.1",
50
50
  "@ast-grep/napi": "0.12.0",
51
- "@modern-js/swc-plugins": "0.6.5",
51
+ "@modern-js/swc-plugins": "0.6.6",
52
52
  "@rollup/pluginutils": "4.1.1",
53
53
  "@svgr/core": "8.0.0",
54
54
  "@svgr/plugin-jsx": "8.0.1",
@@ -67,24 +67,24 @@
67
67
  "tapable": "2.2.1",
68
68
  "terser": "5.19.2",
69
69
  "tsconfig-paths-webpack-plugin": "4.1.0",
70
- "@modern-js/core": "2.42.2",
71
- "@modern-js/plugin": "2.42.2",
72
- "@modern-js/plugin-changeset": "2.42.2",
73
- "@modern-js/plugin-i18n": "2.42.2",
74
- "@modern-js/new-action": "2.42.2",
75
- "@modern-js/plugin-lint": "2.42.2",
76
- "@modern-js/types": "2.42.2",
77
- "@modern-js/utils": "2.42.2",
78
- "@modern-js/upgrade": "2.42.2"
70
+ "@modern-js/core": "2.43.0",
71
+ "@modern-js/new-action": "2.43.0",
72
+ "@modern-js/plugin": "2.43.0",
73
+ "@modern-js/plugin-i18n": "2.43.0",
74
+ "@modern-js/plugin-lint": "2.43.0",
75
+ "@modern-js/plugin-changeset": "2.43.0",
76
+ "@modern-js/types": "2.43.0",
77
+ "@modern-js/upgrade": "2.43.0",
78
+ "@modern-js/utils": "2.43.0"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@types/convert-source-map": "1.5.2",
82
82
  "@types/node": "^14",
83
83
  "typescript": "^5",
84
- "@modern-js/builder-webpack-provider": "2.42.2",
85
- "@modern-js/self": "npm:@modern-js/module-tools@2.42.2",
86
- "@scripts/build": "2.42.2",
87
- "@scripts/vitest-config": "2.42.2"
84
+ "@modern-js/builder-webpack-provider": "2.43.0",
85
+ "@modern-js/self": "npm:@modern-js/module-tools@2.43.0",
86
+ "@scripts/build": "2.43.0",
87
+ "@scripts/vitest-config": "2.43.0"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "typescript": "^4 || ^5"