@modern-js/module-tools 2.46.1 → 2.47.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.
- package/dist/builder/feature/asset.d.ts +2 -2
- package/dist/builder/feature/asset.js +21 -1
- package/dist/builder/feature/redirect.js +4 -4
- package/dist/builder/feature/style/transformStyle.d.ts +1 -1
- package/dist/types/config/dev.d.ts +3 -3
- package/dist/utils/outExtension.d.ts +5 -0
- package/dist/utils/outExtension.js +2 -1
- package/lib/types.d.ts +12 -2
- package/package.json +14 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ICompiler } from '../../types';
|
|
2
|
+
import type { ICompiler } from '../../types';
|
|
3
3
|
export declare const asset: {
|
|
4
4
|
name: string;
|
|
5
5
|
apply(compiler: ICompiler): void;
|
|
@@ -14,5 +14,5 @@ export declare const asset: {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function getAssetContents(this: ICompiler, assetPath: string, rebaseFrom: string, calledOnLoad?: boolean): Promise<{
|
|
16
16
|
contents: string | Buffer;
|
|
17
|
-
loader: "
|
|
17
|
+
loader: "text" | "jsx" | "copy";
|
|
18
18
|
}>;
|
|
@@ -34,6 +34,7 @@ __export(asset_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(asset_exports);
|
|
35
35
|
var import_path = require("path");
|
|
36
36
|
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
|
37
38
|
var import_pluginutils = require("@rollup/pluginutils");
|
|
38
39
|
var import_core = require("../../../compiled/@svgr/core");
|
|
39
40
|
var import_plugin_svgo = __toESM(require("../../../compiled/@svgr/plugin-svgo"));
|
|
@@ -67,6 +68,24 @@ const asset = {
|
|
|
67
68
|
function encodeSVG(buffer) {
|
|
68
69
|
return encodeURIComponent(buffer.toString("utf-8").replace(/[\n\r]/gim, "").replace(/\t/gim, " ").replace(/<!--(.*(?=-->))-->/gim, "").replace(/'/gim, "\\i")).replace(/\(/g, "%28").replace(/\)/g, "%29");
|
|
69
70
|
}
|
|
71
|
+
const getDefaultSVGRConfig = () => ({
|
|
72
|
+
svgo: true,
|
|
73
|
+
svgoConfig: {
|
|
74
|
+
plugins: [
|
|
75
|
+
{
|
|
76
|
+
name: "preset-default",
|
|
77
|
+
params: {
|
|
78
|
+
overrides: {
|
|
79
|
+
// viewBox is required to resize SVGs with CSS.
|
|
80
|
+
// @see https://github.com/svg/svgo/issues/1128
|
|
81
|
+
removeViewBox: false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"prefixIds"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
});
|
|
70
89
|
async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
|
|
71
90
|
const fileContent = await import_fs.default.promises.readFile(assetPath);
|
|
72
91
|
const { buildType, format, outDir } = this.config;
|
|
@@ -80,7 +99,8 @@ async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
|
|
|
80
99
|
let emitAsset = true;
|
|
81
100
|
let contents = normalizedPublicPath;
|
|
82
101
|
let loader = "text";
|
|
83
|
-
const
|
|
102
|
+
const defaultConfig = getDefaultSVGRConfig();
|
|
103
|
+
const config = typeof svgr === "boolean" ? defaultConfig : import_lodash.default.merge(defaultConfig, svgr);
|
|
84
104
|
const filter = (0, import_pluginutils.createFilter)(config.include || SVG_REGEXP, config.exclude);
|
|
85
105
|
if (svgr && filter(assetPath)) {
|
|
86
106
|
const previousExport = config.exportType === "named" ? `export default "${normalizedPublicPath}"` : null;
|
|
@@ -40,7 +40,7 @@ var import_file = require("../../constants/file");
|
|
|
40
40
|
var import_utils2 = require("../../utils");
|
|
41
41
|
var import_asset = require("./asset");
|
|
42
42
|
var import_postcssTransformer = require("./style/postcssTransformer");
|
|
43
|
-
async function redirectImport(compiler, code, modules, aliasRecord, filePath, outputDir, jsExtension, matchPath) {
|
|
43
|
+
async function redirectImport(compiler, code, modules, aliasRecord, filePath, outputDir, jsExtension, isModule, matchPath) {
|
|
44
44
|
const str = new import_magic_string.default(code);
|
|
45
45
|
const extensions = [
|
|
46
46
|
".ts",
|
|
@@ -77,7 +77,7 @@ async function redirectImport(compiler, code, modules, aliasRecord, filePath, ou
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
if (redirect2.autoExtension) {
|
|
80
|
-
if (ext === "" && jsExtension !== ".js"
|
|
80
|
+
if (ext === "" && name2.startsWith(".") && (jsExtension !== ".js" || isModule)) {
|
|
81
81
|
str.overwrite(start, end, `${name2}${jsExtension}`);
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
@@ -214,13 +214,13 @@ const redirect = {
|
|
|
214
214
|
if (!matchModule.length) {
|
|
215
215
|
return args;
|
|
216
216
|
}
|
|
217
|
-
const { jsExtension } = (0, import_utils2.getDefaultOutExtension)({
|
|
217
|
+
const { jsExtension, isModule } = (0, import_utils2.getDefaultOutExtension)({
|
|
218
218
|
format,
|
|
219
219
|
root,
|
|
220
220
|
autoExtension
|
|
221
221
|
});
|
|
222
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, matchPath);
|
|
223
|
+
const str = await redirectImport(compiler, code, matchModule, absoluteAlias, id, (0, import_path.dirname)(outputPath), jsExtension, isModule, matchPath);
|
|
224
224
|
return {
|
|
225
225
|
...args,
|
|
226
226
|
code: str.toString(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ToolsConfig
|
|
1
|
+
import type { ToolsConfig } from '@rsbuild/core';
|
|
2
2
|
export interface StorybookBuildConfig {
|
|
3
|
-
webpack?:
|
|
4
|
-
webpackChain?:
|
|
3
|
+
webpack?: ToolsConfig['webpack'];
|
|
4
|
+
webpackChain?: ToolsConfig['webpackChain'];
|
|
5
5
|
}
|
|
6
6
|
export interface Dev {
|
|
7
7
|
storybook?: StorybookBuildConfig;
|
package/lib/types.d.ts
CHANGED
|
@@ -34,8 +34,18 @@ declare module '*.webp' {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
declare module '*.svg' {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
import * as React from 'react';
|
|
38
|
+
|
|
39
|
+
export const ReactComponent: React.FunctionComponent<
|
|
40
|
+
React.SVGProps<SVGSVGElement>
|
|
41
|
+
>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The default export type depends on the asset.svgr.exportType config,
|
|
45
|
+
* it can be a string or a ReactComponent
|
|
46
|
+
* */
|
|
47
|
+
const content: any;
|
|
48
|
+
export default content;
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
declare module '*.css' {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.47.1",
|
|
4
4
|
"description": "Simple, powerful, high-performance modern npm package development solution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modern",
|
|
@@ -66,24 +66,24 @@
|
|
|
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/new-action": "2.
|
|
71
|
-
"@modern-js/plugin
|
|
72
|
-
"@modern-js/plugin": "2.
|
|
73
|
-
"@modern-js/plugin-i18n": "2.
|
|
74
|
-
"@modern-js/
|
|
75
|
-
"@modern-js/
|
|
76
|
-
"@modern-js/upgrade": "2.
|
|
77
|
-
"@modern-js/utils": "2.
|
|
69
|
+
"@modern-js/core": "2.47.1",
|
|
70
|
+
"@modern-js/new-action": "2.47.1",
|
|
71
|
+
"@modern-js/plugin": "2.47.1",
|
|
72
|
+
"@modern-js/plugin-changeset": "2.47.1",
|
|
73
|
+
"@modern-js/plugin-i18n": "2.47.1",
|
|
74
|
+
"@modern-js/types": "2.47.1",
|
|
75
|
+
"@modern-js/plugin-lint": "2.47.1",
|
|
76
|
+
"@modern-js/upgrade": "2.47.1",
|
|
77
|
+
"@modern-js/utils": "2.47.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
+
"@rsbuild/core": "0.4.6",
|
|
80
81
|
"@types/convert-source-map": "1.5.2",
|
|
81
82
|
"@types/node": "^14",
|
|
82
83
|
"typescript": "^5",
|
|
83
|
-
"@modern-js/
|
|
84
|
-
"@
|
|
85
|
-
"@scripts/vitest-config": "2.
|
|
86
|
-
"@scripts/build": "2.46.1"
|
|
84
|
+
"@modern-js/self": "npm:@modern-js/module-tools@2.47.1",
|
|
85
|
+
"@scripts/build": "2.47.1",
|
|
86
|
+
"@scripts/vitest-config": "2.47.1"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"typescript": "^4 || ^5"
|