@modern-js/module-tools 2.48.4 → 2.48.5
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/feature/asset.js +1 -1
- package/dist/builder/feature/redirect.js +8 -4
- package/dist/utils/dts.js +57 -35
- package/package.json +15 -11
|
@@ -102,7 +102,7 @@ async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
|
|
|
102
102
|
const defaultConfig = getDefaultSVGRConfig();
|
|
103
103
|
const config = typeof svgr === "boolean" ? defaultConfig : import_lodash.default.merge(defaultConfig, svgr);
|
|
104
104
|
const filter = (0, import_pluginutils.createFilter)(config.include || SVG_REGEXP, config.exclude);
|
|
105
|
-
if (svgr && filter(assetPath)) {
|
|
105
|
+
if (svgr && filter(assetPath) && calledOnLoad) {
|
|
106
106
|
const previousExport = config.exportType === "named" ? `export default "${normalizedPublicPath}"` : null;
|
|
107
107
|
contents = await (0, import_core.transform)(fileContent.toString(), config, {
|
|
108
108
|
filePath: assetPath,
|
|
@@ -119,10 +119,14 @@ async function redirectImport(compiler, code, modules, aliasRecord, filePath, ou
|
|
|
119
119
|
if (redirect2.asset) {
|
|
120
120
|
if (import_file.assetExt.filter((ext2) => name2.endsWith(ext2)).length) {
|
|
121
121
|
const absPath = (0, import_path.resolve)((0, import_path.dirname)(filePath), name2);
|
|
122
|
-
const { contents: relativeImportPath, loader } =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
const { contents: relativeImportPath, loader } = (
|
|
123
|
+
// HACK: set callOnLoad true to invoke svgr
|
|
124
|
+
await import_asset.getAssetContents.apply(compiler, [
|
|
125
|
+
absPath,
|
|
126
|
+
outputDir,
|
|
127
|
+
true
|
|
128
|
+
])
|
|
129
|
+
);
|
|
126
130
|
if (loader === "jsx") {
|
|
127
131
|
const ext2 = (0, import_path.extname)(name2);
|
|
128
132
|
const outputName = `${name2.slice(0, -ext2.length)}.js`;
|
package/dist/utils/dts.js
CHANGED
|
@@ -113,54 +113,76 @@ const processDtsFilesAfterTsc = async (config) => {
|
|
|
113
113
|
}
|
|
114
114
|
const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
|
|
115
115
|
const matchPath = (0, import_tsconfig_paths.createMatchPath)(absoluteBaseUrl, paths, mainFields, addMatchAll);
|
|
116
|
-
const Pattern = [
|
|
117
|
-
`import $VAR from '$MATCH'`,
|
|
118
|
-
`import $VAR from "$MATCH"`,
|
|
119
|
-
`export {$$$VAR} from '$MATCH'`,
|
|
120
|
-
`export {$$$VAR} from "$MATCH"`,
|
|
121
|
-
`export * from '$MATCH'`,
|
|
122
|
-
`export * from "$MATCH"`,
|
|
123
|
-
`export * as $VAR from '$MATCH'`,
|
|
124
|
-
`export * as $VAR from "$MATCH"`,
|
|
125
|
-
`import('$MATCH')`,
|
|
126
|
-
`import("$MATCH")`
|
|
127
|
-
];
|
|
128
116
|
await Promise.all(dtsFilesPath.map((filePath) => {
|
|
129
117
|
var _userTsconfig_compilerOptions;
|
|
130
118
|
const code = import_utils.fs.readFileSync(filePath, "utf8");
|
|
131
|
-
|
|
119
|
+
const str = new import_magic_string.default(code);
|
|
120
|
+
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));
|
|
132
121
|
try {
|
|
133
|
-
const sgNode = import_napi.
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
const sgNode = import_napi.js.parse(code).root();
|
|
123
|
+
const matcher = {
|
|
124
|
+
rule: {
|
|
125
|
+
kind: "string_fragment",
|
|
126
|
+
any: [
|
|
127
|
+
{
|
|
128
|
+
inside: {
|
|
129
|
+
stopBy: "end",
|
|
130
|
+
kind: "import_statement",
|
|
131
|
+
field: "source"
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
inside: {
|
|
136
|
+
stopBy: "end",
|
|
137
|
+
kind: "export_statement",
|
|
138
|
+
field: "source"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
inside: {
|
|
143
|
+
kind: "string",
|
|
144
|
+
inside: {
|
|
145
|
+
kind: "arguments",
|
|
146
|
+
inside: {
|
|
147
|
+
kind: "call_expression",
|
|
148
|
+
has: {
|
|
149
|
+
field: "function",
|
|
150
|
+
regex: "^(import|require)$"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const matchModule = sgNode.findAll(matcher).map((matchNode) => {
|
|
136
160
|
return {
|
|
137
161
|
name: matchNode.text(),
|
|
138
162
|
start: matchNode.range().start.index,
|
|
139
163
|
end: matchNode.range().end.index
|
|
140
164
|
};
|
|
141
165
|
});
|
|
166
|
+
matchModule.forEach((module2) => {
|
|
167
|
+
if (!module2.name) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const { start, end, name } = module2;
|
|
171
|
+
const absoluteImportPath = matchPath(name, void 0, void 0, [
|
|
172
|
+
".jsx",
|
|
173
|
+
".tsx",
|
|
174
|
+
".js",
|
|
175
|
+
".ts"
|
|
176
|
+
]);
|
|
177
|
+
if (absoluteImportPath) {
|
|
178
|
+
const relativePath = (0, import_path.relative)((0, import_path.dirname)(originalFilePath), absoluteImportPath);
|
|
179
|
+
const relativeImportPath = (0, import_builder.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
|
|
180
|
+
str.overwrite(start, end, relativeImportPath);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
142
183
|
} catch (e) {
|
|
143
184
|
import_utils.logger.error("[parse error]", e);
|
|
144
185
|
}
|
|
145
|
-
const str = new import_magic_string.default(code);
|
|
146
|
-
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));
|
|
147
|
-
matchModule.forEach((module2) => {
|
|
148
|
-
if (!module2.name) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const { start, end, name } = module2;
|
|
152
|
-
const absoluteImportPath = matchPath(name, void 0, void 0, [
|
|
153
|
-
".jsx",
|
|
154
|
-
".tsx",
|
|
155
|
-
".js",
|
|
156
|
-
".ts"
|
|
157
|
-
]);
|
|
158
|
-
if (absoluteImportPath) {
|
|
159
|
-
const relativePath = (0, import_path.relative)((0, import_path.dirname)(originalFilePath), absoluteImportPath);
|
|
160
|
-
const relativeImportPath = (0, import_builder.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
|
|
161
|
-
str.overwrite(start, end, relativeImportPath);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
186
|
banner && str.prepend(`${banner}
|
|
165
187
|
`);
|
|
166
188
|
footer && str.append(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools",
|
|
3
|
-
"version": "2.48.
|
|
3
|
+
"version": "2.48.5",
|
|
4
4
|
"description": "Simple, powerful, high-performance modern npm package development solution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modern",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"./defineConfig": {
|
|
25
25
|
"jsnext:source": "./src/config/defineConfig.ts",
|
|
26
26
|
"default": "./dist/config/defineConfig.js"
|
|
27
|
+
},
|
|
28
|
+
"./utils": {
|
|
29
|
+
"jsnext:source": "./src/utils/index.ts",
|
|
30
|
+
"default": "./dist/utils/assert.js"
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"main": "./dist/index.js",
|
|
@@ -66,22 +70,22 @@
|
|
|
66
70
|
"tapable": "2.2.1",
|
|
67
71
|
"terser": "5.19.2",
|
|
68
72
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
69
|
-
"@modern-js/core": "2.48.
|
|
70
|
-
"@modern-js/plugin
|
|
71
|
-
"@modern-js/plugin-
|
|
72
|
-
"@modern-js/
|
|
73
|
-
"@modern-js/plugin": "2.48.
|
|
74
|
-
"@modern-js/
|
|
75
|
-
"@modern-js/
|
|
73
|
+
"@modern-js/core": "2.48.5",
|
|
74
|
+
"@modern-js/plugin": "2.48.5",
|
|
75
|
+
"@modern-js/plugin-i18n": "2.48.5",
|
|
76
|
+
"@modern-js/types": "2.48.5",
|
|
77
|
+
"@modern-js/plugin-lint": "2.48.5",
|
|
78
|
+
"@modern-js/plugin-changeset": "2.48.5",
|
|
79
|
+
"@modern-js/utils": "2.48.5"
|
|
76
80
|
},
|
|
77
81
|
"devDependencies": {
|
|
78
82
|
"@rsbuild/core": "0.5.4",
|
|
79
83
|
"@types/convert-source-map": "1.5.2",
|
|
80
84
|
"@types/node": "^14",
|
|
81
85
|
"typescript": "^5",
|
|
82
|
-
"@modern-js/self": "npm:@modern-js/module-tools@2.48.
|
|
83
|
-
"@scripts/build": "2.48.
|
|
84
|
-
"@scripts/vitest-config": "2.48.
|
|
86
|
+
"@modern-js/self": "npm:@modern-js/module-tools@2.48.5",
|
|
87
|
+
"@scripts/build": "2.48.5",
|
|
88
|
+
"@scripts/vitest-config": "2.48.5"
|
|
85
89
|
},
|
|
86
90
|
"peerDependencies": {
|
|
87
91
|
"typescript": "^4 || ^5"
|