@modern-js/module-tools 2.36.0 → 2.37.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.
- package/dist/builder/build.d.ts +0 -1
- package/dist/builder/esbuild/adapter.js +16 -5
- package/dist/builder/esbuild/index.d.ts +1 -1
- package/dist/builder/esbuild/index.js +2 -2
- package/dist/builder/esbuild/resolve.d.ts +2 -1
- package/dist/builder/esbuild/resolve.js +30 -15
- package/dist/builder/feature/index.js +3 -3
- package/dist/builder/feature/redirect.js +8 -2
- package/dist/builder/feature/style/utils.js +16 -10
- package/dist/builder/index.d.ts +0 -1
- package/dist/config/merge.d.ts +0 -1
- package/dist/config/normalize.d.ts +0 -1
- package/dist/constants/preset.d.ts +4 -4
- package/dist/types/esbuild.d.ts +1 -1
- package/package.json +16 -19
package/dist/builder/build.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ __export(adapter_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(adapter_exports);
|
|
34
34
|
var import_path = require("path");
|
|
35
35
|
var import_module = __toESM(require("module"));
|
|
36
|
-
var import_picomatch = __toESM(require("picomatch"));
|
|
37
36
|
var import_utils = require("@modern-js/utils");
|
|
38
37
|
var import_pluginutils = require("@rollup/pluginutils");
|
|
39
38
|
var import_utils2 = require("../../utils");
|
|
@@ -64,8 +63,7 @@ const adapterPlugin = (compiler) => {
|
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
65
|
for (const [key] of Object.entries(config.umdGlobals)) {
|
|
67
|
-
|
|
68
|
-
if (isMatch(args.path)) {
|
|
66
|
+
if (args.path === key) {
|
|
69
67
|
(0, import_debug.debugResolve)("resolve umdGlobals:", key);
|
|
70
68
|
return {
|
|
71
69
|
path: args.path,
|
|
@@ -155,9 +153,17 @@ const adapterPlugin = (compiler) => {
|
|
|
155
153
|
const isExternal = getIsExternal(originalFilePath);
|
|
156
154
|
var _args_resolveDir;
|
|
157
155
|
const dir = (_args_resolveDir = args.resolveDir) !== null && _args_resolveDir !== void 0 ? _args_resolveDir : args.importer ? (0, import_path.dirname)(args.importer) : root;
|
|
158
|
-
const
|
|
156
|
+
const resultPath = isExternal ? args.path : getResultPath(originalFilePath, dir, args.kind);
|
|
157
|
+
if (resultPath === false) {
|
|
158
|
+
(0, import_debug.debugResolve)("empty resolve:", args);
|
|
159
|
+
return {
|
|
160
|
+
path: "/empty-stub",
|
|
161
|
+
sideEffects: false
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const sideEffects = await getSideEffects(resultPath, isExternal);
|
|
159
165
|
const result = {
|
|
160
|
-
path:
|
|
166
|
+
path: resultPath,
|
|
161
167
|
external: isExternal,
|
|
162
168
|
namespace: isExternal ? void 0 : "file",
|
|
163
169
|
sideEffects,
|
|
@@ -182,6 +188,11 @@ const adapterPlugin = (compiler) => {
|
|
|
182
188
|
if (args.namespace !== "file") {
|
|
183
189
|
return;
|
|
184
190
|
}
|
|
191
|
+
if (args.path === "/empty-stub") {
|
|
192
|
+
return {
|
|
193
|
+
contents: "module.exports = {}"
|
|
194
|
+
};
|
|
195
|
+
}
|
|
185
196
|
compiler.addWatchFile(args.path);
|
|
186
197
|
let result = await compiler.hooks.load.promise(args);
|
|
187
198
|
if (!result) {
|
|
@@ -16,7 +16,7 @@ export declare class EsbuildCompiler implements ICompiler {
|
|
|
16
16
|
outputChunk: Map<string, Chunk>;
|
|
17
17
|
watchedFiles: Set<string>;
|
|
18
18
|
css_resolve: (id: string, dir: string) => string;
|
|
19
|
-
node_resolve: (id: string, dir: string, kind: ImportKind) => string;
|
|
19
|
+
node_resolve: (id: string, dir: string, kind: ImportKind) => string | false;
|
|
20
20
|
watcher?: FSWatcher;
|
|
21
21
|
virtualModule: Map<string, string>;
|
|
22
22
|
private transformContextMap;
|
|
@@ -243,13 +243,13 @@ class EsbuildCompiler {
|
|
|
243
243
|
tsconfig: config.tsconfig,
|
|
244
244
|
mainFields: config.resolve.mainFields
|
|
245
245
|
};
|
|
246
|
-
this.css_resolve = (0, import_resolve.
|
|
246
|
+
this.css_resolve = (0, import_resolve.createCssResolver)({
|
|
247
247
|
...resolveOptions,
|
|
248
248
|
resolveType: "css",
|
|
249
249
|
extensions: import_build.cssExtensions,
|
|
250
250
|
preferRelative: true
|
|
251
251
|
});
|
|
252
|
-
this.node_resolve = (0, import_resolve.
|
|
252
|
+
this.node_resolve = (0, import_resolve.createJsResolver)({
|
|
253
253
|
...resolveOptions,
|
|
254
254
|
resolveType: "js",
|
|
255
255
|
extensions: config.resolve.jsExtensions
|
|
@@ -3,7 +3,8 @@ import { ImportKind, Platform } from 'esbuild';
|
|
|
3
3
|
* supports require js plugin in less file
|
|
4
4
|
*/
|
|
5
5
|
export declare const cssExtensions: string[];
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const createJsResolver: (options: ResolverOptions) => (id: string, dir: string, kind?: ImportKind) => string | false;
|
|
7
|
+
export declare const createCssResolver: (options: ResolverOptions) => (id: string, dir: string, kind?: ImportKind) => string;
|
|
7
8
|
interface ResolverOptions {
|
|
8
9
|
platform: Platform;
|
|
9
10
|
resolveType: 'js' | 'css';
|
|
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var resolve_exports = {};
|
|
30
30
|
__export(resolve_exports, {
|
|
31
|
-
|
|
31
|
+
createCssResolver: () => createCssResolver,
|
|
32
|
+
createJsResolver: () => createJsResolver,
|
|
32
33
|
cssExtensions: () => cssExtensions
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(resolve_exports);
|
|
@@ -47,7 +48,6 @@ function createEnhancedResolve(options) {
|
|
|
47
48
|
const { tsconfig } = options;
|
|
48
49
|
if (import_fs.default.existsSync(tsconfig)) {
|
|
49
50
|
plugins.push(new import_tsconfig_paths_webpack_plugin.default({
|
|
50
|
-
baseUrl: options.root,
|
|
51
51
|
configFile: tsconfig
|
|
52
52
|
}));
|
|
53
53
|
}
|
|
@@ -87,7 +87,7 @@ function createEnhancedResolve(options) {
|
|
|
87
87
|
esmResolveSync
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
const
|
|
90
|
+
const createJsResolver = (options) => {
|
|
91
91
|
const resolveCache = /* @__PURE__ */ new Map();
|
|
92
92
|
const { resolveSync, esmResolveSync } = createEnhancedResolve(options);
|
|
93
93
|
const resolver = (id, dir, kind) => {
|
|
@@ -97,18 +97,32 @@ const createResolver = (options) => {
|
|
|
97
97
|
return cacheResult;
|
|
98
98
|
}
|
|
99
99
|
let result;
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
result = esmResolveSync(dir, id);
|
|
103
|
-
} else {
|
|
104
|
-
result = resolveSync(dir, id);
|
|
105
|
-
}
|
|
100
|
+
if (kind === "import-statement" || kind === "dynamic-import") {
|
|
101
|
+
result = esmResolveSync(dir, id);
|
|
106
102
|
} else {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
result = resolveSync(dir, id);
|
|
104
|
+
}
|
|
105
|
+
if (result) {
|
|
106
|
+
resolveCache.set(cacheKey, result);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
return resolver;
|
|
111
|
+
};
|
|
112
|
+
const createCssResolver = (options) => {
|
|
113
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
114
|
+
const { resolveSync } = createEnhancedResolve(options);
|
|
115
|
+
const resolver = (id, dir, kind) => {
|
|
116
|
+
const cacheKey = id + dir + (kind || "");
|
|
117
|
+
const cacheResult = resolveCache.get(cacheKey);
|
|
118
|
+
if (cacheResult) {
|
|
119
|
+
return cacheResult;
|
|
120
|
+
}
|
|
121
|
+
let result;
|
|
122
|
+
try {
|
|
123
|
+
result = resolveSync(dir, id);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
result = resolveSync(dir, id.replace(/^~/, ""));
|
|
112
126
|
}
|
|
113
127
|
if (!result) {
|
|
114
128
|
throw new Error(`can not resolve ${id} from ${dir}`);
|
|
@@ -120,6 +134,7 @@ const createResolver = (options) => {
|
|
|
120
134
|
};
|
|
121
135
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
136
|
0 && (module.exports = {
|
|
123
|
-
|
|
137
|
+
createCssResolver,
|
|
138
|
+
createJsResolver,
|
|
124
139
|
cssExtensions
|
|
125
140
|
});
|
|
@@ -49,9 +49,6 @@ async function getInternalList(context) {
|
|
|
49
49
|
const { json } = await Promise.resolve().then(() => __toESM(require("./json")));
|
|
50
50
|
internal.push(redirect, json);
|
|
51
51
|
}
|
|
52
|
-
if (config.minify && config.minify !== "esbuild") {
|
|
53
|
-
internal.push(import_terser.minify);
|
|
54
|
-
}
|
|
55
52
|
const userTsconfig = await (0, import_dts.getProjectTsconfig)(context.config.tsconfig);
|
|
56
53
|
var _userTsconfig_compilerOptions_emitDecoratorMetadata;
|
|
57
54
|
const emitDecoratorMetadata = (_userTsconfig_compilerOptions_emitDecoratorMetadata = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.emitDecoratorMetadata) !== null && _userTsconfig_compilerOptions_emitDecoratorMetadata !== void 0 ? _userTsconfig_compilerOptions_emitDecoratorMetadata : false;
|
|
@@ -66,6 +63,9 @@ async function getInternalList(context) {
|
|
|
66
63
|
const { swcRenderChunk } = await Promise.resolve().then(() => __toESM(require("./swc")));
|
|
67
64
|
internal.push(swcRenderChunk);
|
|
68
65
|
}
|
|
66
|
+
if (config.minify && config.minify !== "esbuild") {
|
|
67
|
+
internal.push(import_terser.minify);
|
|
68
|
+
}
|
|
69
69
|
return internal;
|
|
70
70
|
}
|
|
71
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -165,8 +165,14 @@ const redirect = {
|
|
|
165
165
|
`import($MATCH)`
|
|
166
166
|
];
|
|
167
167
|
const staticPattern = [
|
|
168
|
-
`import
|
|
169
|
-
`import
|
|
168
|
+
`import $VAR from '$MATCH'`,
|
|
169
|
+
`import $VAR from "$MATCH"`,
|
|
170
|
+
`export {$$$VAR} from '$MATCH'`,
|
|
171
|
+
`export {$$$VAR} from "$MATCH"`,
|
|
172
|
+
`export * from '$MATCH'`,
|
|
173
|
+
`export * from "$MATCH"`,
|
|
174
|
+
`export * as $VAR from '$MATCH'`,
|
|
175
|
+
`export * as $VAR from "$MATCH"`,
|
|
170
176
|
`import '$MATCH'`,
|
|
171
177
|
`import "$MATCH"`
|
|
172
178
|
];
|
|
@@ -77,16 +77,22 @@ async function rebaseUrls(filepath, rootDir, resolver) {
|
|
|
77
77
|
file
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
try {
|
|
81
|
+
const rebased = await rewriteCssUrls(content, import_path.default.extname(file).slice(1), (url) => {
|
|
82
|
+
if (url.startsWith("/")) {
|
|
83
|
+
return url;
|
|
84
|
+
}
|
|
85
|
+
return resolver(url, fileDir);
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
file,
|
|
89
|
+
contents: rebased
|
|
90
|
+
};
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return {
|
|
93
|
+
file
|
|
94
|
+
};
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
function rewriteCssUrls(css, type, replacer) {
|
|
92
98
|
return asyncReplace(css, cssUrlRE, async (match) => {
|
package/dist/builder/index.d.ts
CHANGED
package/dist/config/merge.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="mocha" />
|
|
2
1
|
import { ModuleContext } from '../types';
|
|
3
2
|
import type { BaseBuildConfig, PartialBaseBuildConfig, ModuleLegacyUserConfig, BuildCommandOptions } from '../types';
|
|
4
3
|
export declare const mergeDefaultBaseConfig: (pConfig: PartialBaseBuildConfig, options: {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="mocha" />
|
|
2
1
|
import type { PluginAPI } from '@modern-js/core';
|
|
3
2
|
import type { BaseBuildConfig, BuildPreset, PartialBuildConfig, PartialBaseBuildConfig, ModuleContext, BuildCommandOptions, ModuleTools } from '../types';
|
|
4
3
|
export declare const presetToConfig: (preset?: BuildPreset) => Promise<PartialBaseBuildConfig[] | undefined>;
|
|
@@ -7,19 +7,19 @@ export declare const npmComponentWithUmdPresetConfig: PartialBaseBuildConfig[];
|
|
|
7
7
|
export declare const libraryPreset: {
|
|
8
8
|
'npm-library': PartialBaseBuildConfig[];
|
|
9
9
|
};
|
|
10
|
-
export declare const libraryPresetWithTarget: Record<"npm-library-
|
|
10
|
+
export declare const libraryPresetWithTarget: Record<"npm-library-es6" | "npm-library-esnext" | "npm-library-es5" | "npm-library-es2015" | "npm-library-es2016" | "npm-library-es2017" | "npm-library-es2018" | "npm-library-es2019" | "npm-library-es2020" | "npm-library-es2021" | "npm-library-es2022", PartialBaseBuildConfig[]>;
|
|
11
11
|
export declare const libraryUmdPreset: {
|
|
12
12
|
'npm-library-with-umd': PartialBaseBuildConfig[];
|
|
13
13
|
};
|
|
14
|
-
export declare const libraryUmdPresetWithTarget: Record<"npm-library-with-umd-
|
|
14
|
+
export declare const libraryUmdPresetWithTarget: Record<"npm-library-with-umd-es6" | "npm-library-with-umd-esnext" | "npm-library-with-umd-es5" | "npm-library-with-umd-es2015" | "npm-library-with-umd-es2016" | "npm-library-with-umd-es2017" | "npm-library-with-umd-es2018" | "npm-library-with-umd-es2019" | "npm-library-with-umd-es2020" | "npm-library-with-umd-es2021" | "npm-library-with-umd-es2022", PartialBaseBuildConfig[]>;
|
|
15
15
|
export declare const componentPreset: {
|
|
16
16
|
'npm-component': PartialBaseBuildConfig[];
|
|
17
17
|
};
|
|
18
|
-
export declare const componentPresetWithTarget: Record<"npm-component-
|
|
18
|
+
export declare const componentPresetWithTarget: Record<"npm-component-es6" | "npm-component-esnext" | "npm-component-es5" | "npm-component-es2015" | "npm-component-es2016" | "npm-component-es2017" | "npm-component-es2018" | "npm-component-es2019" | "npm-component-es2020" | "npm-component-es2021" | "npm-component-es2022", PartialBaseBuildConfig[]>;
|
|
19
19
|
export declare const componentUmdPreset: {
|
|
20
20
|
'npm-component-with-umd': PartialBaseBuildConfig[];
|
|
21
21
|
};
|
|
22
|
-
export declare const componentUmdPresetWithTarget: Record<"npm-component-with-umd-
|
|
22
|
+
export declare const componentUmdPresetWithTarget: Record<"npm-component-with-umd-es6" | "npm-component-with-umd-esnext" | "npm-component-with-umd-es5" | "npm-component-with-umd-es2015" | "npm-component-with-umd-es2016" | "npm-component-with-umd-es2017" | "npm-component-with-umd-es2018" | "npm-component-with-umd-es2019" | "npm-component-with-umd-es2020" | "npm-component-with-umd-es2021" | "npm-component-with-umd-es2022", PartialBaseBuildConfig[]>;
|
|
23
23
|
export declare const nodeBuildConfig: PartialBaseBuildConfig[];
|
|
24
24
|
export declare const universalBuildConfig: PartialBaseBuildConfig[];
|
|
25
25
|
export declare const presetList: Record<string, PartialBaseBuildConfig[]>;
|
package/dist/types/esbuild.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type Context = {
|
|
|
37
37
|
export interface ICompiler {
|
|
38
38
|
reBuild: (type: 'link' | 'change', config: BaseBuildConfig) => Promise<void>;
|
|
39
39
|
css_resolve: (id: string, dir: string) => string;
|
|
40
|
-
node_resolve: (id: string, dir: string, kind: ImportKind) => string;
|
|
40
|
+
node_resolve: (id: string, dir: string, kind: ImportKind) => string | false;
|
|
41
41
|
init: () => Promise<void>;
|
|
42
42
|
watcher?: FSWatcher;
|
|
43
43
|
instance?: BuildContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.37.0",
|
|
4
4
|
"description": "Simple, powerful, high-performance modern npm package development solution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modern",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@ast-grep/napi": "0.12.0",
|
|
51
51
|
"@babel/generator": "^7.22.15",
|
|
52
52
|
"@babel/parser": "^7.22.15",
|
|
53
|
-
"@babel/traverse": "7.
|
|
53
|
+
"@babel/traverse": "7.23.2",
|
|
54
54
|
"@babel/types": "^7.22.15",
|
|
55
55
|
"@modern-js/swc-plugins": "0.6.4",
|
|
56
56
|
"@rollup/pluginutils": "4.1.1",
|
|
@@ -62,7 +62,6 @@
|
|
|
62
62
|
"enhanced-resolve": "5.8.3",
|
|
63
63
|
"esbuild": "0.19.2",
|
|
64
64
|
"magic-string": "0.26.4",
|
|
65
|
-
"picomatch": "2.3.0",
|
|
66
65
|
"postcss": "8.4.31",
|
|
67
66
|
"postcss-modules": "4.3.0",
|
|
68
67
|
"safe-identifier": "0.4.2",
|
|
@@ -72,28 +71,26 @@
|
|
|
72
71
|
"tapable": "2.2.1",
|
|
73
72
|
"terser": "5.19.2",
|
|
74
73
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
75
|
-
"@modern-js/core": "2.
|
|
76
|
-
"@modern-js/new-action": "2.
|
|
77
|
-
"@modern-js/
|
|
78
|
-
"@modern-js/plugin": "2.
|
|
79
|
-
"@modern-js/plugin-
|
|
80
|
-
"@modern-js/plugin-
|
|
81
|
-
"@modern-js/
|
|
82
|
-
"@modern-js/upgrade": "2.
|
|
83
|
-
"@modern-js/utils": "2.
|
|
74
|
+
"@modern-js/core": "2.37.0",
|
|
75
|
+
"@modern-js/new-action": "2.37.0",
|
|
76
|
+
"@modern-js/plugin": "2.37.0",
|
|
77
|
+
"@modern-js/plugin-changeset": "2.37.0",
|
|
78
|
+
"@modern-js/plugin-i18n": "2.37.0",
|
|
79
|
+
"@modern-js/plugin-lint": "2.37.0",
|
|
80
|
+
"@modern-js/types": "2.37.0",
|
|
81
|
+
"@modern-js/upgrade": "2.37.0",
|
|
82
|
+
"@modern-js/utils": "2.37.0"
|
|
84
83
|
},
|
|
85
84
|
"devDependencies": {
|
|
86
85
|
"@types/babel__generator": "7.6.4",
|
|
87
86
|
"@types/babel__traverse": "7.18.5",
|
|
88
87
|
"@types/convert-source-map": "1.5.2",
|
|
89
|
-
"@types/mocha": "9.0.0",
|
|
90
88
|
"@types/node": "^14",
|
|
91
|
-
"@types/picomatch": "2.3.0",
|
|
92
89
|
"typescript": "^5",
|
|
93
|
-
"@modern-js/
|
|
94
|
-
"@modern-js/
|
|
95
|
-
"@scripts/build": "2.
|
|
96
|
-
"@scripts/vitest-config": "2.
|
|
90
|
+
"@modern-js/builder-webpack-provider": "2.37.0",
|
|
91
|
+
"@modern-js/self": "npm:@modern-js/module-tools@2.37.0",
|
|
92
|
+
"@scripts/build": "2.37.0",
|
|
93
|
+
"@scripts/vitest-config": "2.37.0"
|
|
97
94
|
},
|
|
98
95
|
"peerDependencies": {
|
|
99
96
|
"typescript": "^4 || ^5"
|
|
@@ -117,6 +114,6 @@
|
|
|
117
114
|
"new": "modern-lib new",
|
|
118
115
|
"test": "vitest run",
|
|
119
116
|
"test:ui": "vitest --ui",
|
|
120
|
-
"test:watch": "vitest dev
|
|
117
|
+
"test:watch": "vitest dev"
|
|
121
118
|
}
|
|
122
119
|
}
|