@modern-js/module-tools 2.47.1 → 2.48.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/bin/modern.js +7 -1
- package/dist/builder/feature/asset.js +22 -2
- package/dist/command.js +6 -5
- package/dist/constants/build.js +2 -1
- package/dist/types/config/index.d.ts +4 -0
- package/package.json +12 -14
package/bin/modern.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const { INTERNAL_MODULE_TOOLS_PLUGINS } = require('@modern-js/utils');
|
|
3
3
|
|
|
4
|
+
const { version } = require('../package.json');
|
|
5
|
+
|
|
6
|
+
if (!process.env.MODERN_JS_VERSION) {
|
|
7
|
+
process.env.MODERN_JS_VERSION = version;
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
require('@modern-js/core/runBin').run({
|
|
5
11
|
internalPlugins: {
|
|
6
12
|
cli: INTERNAL_MODULE_TOOLS_PLUGINS,
|
|
7
13
|
},
|
|
8
|
-
initialLog: `Modern.js Module v${
|
|
14
|
+
initialLog: `Modern.js Module v${version}`,
|
|
9
15
|
});
|
|
@@ -89,9 +89,9 @@ const getDefaultSVGRConfig = () => ({
|
|
|
89
89
|
async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
|
|
90
90
|
const fileContent = await import_fs.default.promises.readFile(assetPath);
|
|
91
91
|
const { buildType, format, outDir } = this.config;
|
|
92
|
-
const { limit, path, publicPath, svgr } = this.config.asset;
|
|
92
|
+
const { limit, path, publicPath, svgr, name: name2 } = this.config.asset;
|
|
93
93
|
const hash = (0, import_utils.getHash)(fileContent, null).slice(0, 8);
|
|
94
|
-
const outputFileName = (
|
|
94
|
+
const outputFileName = getOutputFileName(assetPath, name2, hash);
|
|
95
95
|
const outputFilePath = (0, import_path.resolve)(outDir, path, outputFileName);
|
|
96
96
|
const relativePath = (0, import_path.relative)(rebaseFrom, outputFilePath);
|
|
97
97
|
const normalizedRelativePath = (0, import_utils.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
|
|
@@ -147,6 +147,26 @@ async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
|
|
|
147
147
|
loader
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
+
function getOutputFileName(filePath, assetName, hash) {
|
|
151
|
+
const format = typeof assetName === "function" ? assetName(filePath) : assetName;
|
|
152
|
+
const fileBaseNameArray = (0, import_path.basename)(filePath).split(".");
|
|
153
|
+
var _fileBaseNameArray_pop;
|
|
154
|
+
const extname2 = (_fileBaseNameArray_pop = fileBaseNameArray.pop()) !== null && _fileBaseNameArray_pop !== void 0 ? _fileBaseNameArray_pop : "";
|
|
155
|
+
const fileBaseName = fileBaseNameArray.join(".");
|
|
156
|
+
const outputFileName = format.replace(/(\[[^\]]*\])/g, (str, match) => {
|
|
157
|
+
if (match === "[name]") {
|
|
158
|
+
return fileBaseName;
|
|
159
|
+
}
|
|
160
|
+
if (match === "[ext]") {
|
|
161
|
+
return extname2;
|
|
162
|
+
}
|
|
163
|
+
if (match === "[hash]") {
|
|
164
|
+
return hash;
|
|
165
|
+
}
|
|
166
|
+
return match;
|
|
167
|
+
});
|
|
168
|
+
return outputFileName;
|
|
169
|
+
}
|
|
150
170
|
// Annotate the CommonJS export names for ESM import in node:
|
|
151
171
|
0 && (module.exports = {
|
|
152
172
|
asset,
|
package/dist/command.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(command_exports, {
|
|
|
34
34
|
upgradeCommand: () => upgradeCommand
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(command_exports);
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
37
38
|
var import_locale = require("./locale");
|
|
38
39
|
const initModuleContext = async (api) => {
|
|
39
40
|
const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
@@ -78,18 +79,18 @@ const devCommand = async (program, api) => {
|
|
|
78
79
|
};
|
|
79
80
|
const newCommand = async (program) => {
|
|
80
81
|
program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-c, --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.new.config)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).option("--no-need-install", import_locale.i18n.t(import_locale.localeKeys.command.shared.noNeedInstall)).action(async (options) => {
|
|
81
|
-
const { ModuleNewAction } = await Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
|
|
82
82
|
const { getLocaleLanguage } = await Promise.resolve().then(() => __toESM(require("@modern-js/plugin-i18n/language-detector")));
|
|
83
83
|
const locale = getLocaleLanguage();
|
|
84
|
-
await
|
|
84
|
+
await (0, import_utils.newAction)({
|
|
85
85
|
...options,
|
|
86
86
|
locale: options.lang || locale
|
|
87
|
-
});
|
|
87
|
+
}, "module");
|
|
88
88
|
});
|
|
89
89
|
};
|
|
90
90
|
const upgradeCommand = async (program) => {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(async () => {
|
|
92
|
+
await (0, import_utils.upgradeAction)();
|
|
93
|
+
});
|
|
93
94
|
};
|
|
94
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
96
|
0 && (module.exports = {
|
package/dist/constants/build.js
CHANGED
|
@@ -69,6 +69,10 @@ export interface SvgrOptions extends Config {
|
|
|
69
69
|
exclude?: Parameters<CreateFilter>[1];
|
|
70
70
|
}
|
|
71
71
|
export interface Asset {
|
|
72
|
+
/**
|
|
73
|
+
* @default [name].[hash].[ext]
|
|
74
|
+
*/
|
|
75
|
+
name?: string | ((assetPath: string) => string);
|
|
72
76
|
path?: string;
|
|
73
77
|
limit?: number;
|
|
74
78
|
publicPath?: string | ((filePath: string) => string);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.48.0",
|
|
4
4
|
"description": "Simple, powerful, high-performance modern npm package development solution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modern",
|
|
@@ -66,24 +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.
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@modern-js/plugin": "2.
|
|
72
|
-
"@modern-js/
|
|
73
|
-
"@modern-js/plugin-
|
|
74
|
-
"@modern-js/
|
|
75
|
-
"@modern-js/
|
|
76
|
-
"@modern-js/upgrade": "2.47.1",
|
|
77
|
-
"@modern-js/utils": "2.47.1"
|
|
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"
|
|
78
76
|
},
|
|
79
77
|
"devDependencies": {
|
|
80
|
-
"@rsbuild/core": "0.4.
|
|
78
|
+
"@rsbuild/core": "0.4.8",
|
|
81
79
|
"@types/convert-source-map": "1.5.2",
|
|
82
80
|
"@types/node": "^14",
|
|
83
81
|
"typescript": "^5",
|
|
84
|
-
"@modern-js/self": "npm:@modern-js/module-tools@2.
|
|
85
|
-
"@scripts/build": "2.
|
|
86
|
-
"@scripts/vitest-config": "2.
|
|
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"
|
|
87
85
|
},
|
|
88
86
|
"peerDependencies": {
|
|
89
87
|
"typescript": "^4 || ^5"
|