@modern-js/module-tools 2.40.0 → 2.42.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/build.d.ts +1 -1
- package/dist/build.js +6 -4
- package/dist/builder/build.d.ts +7 -7
- package/dist/builder/build.js +3 -1
- package/dist/builder/clear.d.ts +1 -2
- package/dist/builder/clear.js +2 -8
- package/dist/builder/copy.d.ts +9 -9
- package/dist/builder/dts/index.d.ts +1 -1
- package/dist/builder/dts/rollup.d.ts +1 -13
- package/dist/builder/dts/tsc.d.ts +1 -1
- package/dist/builder/dts/tsc.js +20 -15
- package/dist/builder/esbuild/adapter.d.ts +1 -1
- package/dist/builder/esbuild/hook.d.ts +1 -1
- package/dist/builder/esbuild/index.d.ts +28 -28
- package/dist/builder/esbuild/resolve.d.ts +9 -9
- package/dist/builder/esbuild/sourcemap.d.ts +14 -14
- package/dist/builder/esbuild/transform.d.ts +4 -4
- package/dist/builder/esbuild/watch.d.ts +1 -1
- package/dist/builder/esbuild/write-file.d.ts +1 -1
- package/dist/builder/feature/asset.d.ts +5 -5
- package/dist/builder/feature/format-cjs.d.ts +3 -3
- package/dist/builder/feature/index.d.ts +1 -1
- package/dist/builder/feature/json.d.ts +3 -3
- package/dist/builder/feature/redirect.d.ts +3 -3
- package/dist/builder/feature/style/index.d.ts +3 -3
- package/dist/builder/feature/style/lessAliasPlugin.d.ts +7 -7
- package/dist/builder/feature/style/lessAliasPlugin.js +3 -2
- package/dist/builder/feature/style/lessRender.d.ts +1 -1
- package/dist/builder/feature/style/postcssTransformer.d.ts +3 -3
- package/dist/builder/feature/style/postcssUrlPlugin.d.ts +3 -3
- package/dist/builder/feature/style/sassRender.d.ts +1 -1
- package/dist/builder/feature/style/transformStyle.d.ts +7 -7
- package/dist/builder/feature/style/utils.d.ts +3 -3
- package/dist/builder/feature/swc.d.ts +5 -5
- package/dist/builder/feature/terser.d.ts +3 -3
- package/dist/builder/index.d.ts +4 -4
- package/dist/builder/index.js +5 -6
- package/dist/builder/platform.d.ts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/command.d.ts +1 -1
- package/dist/config/defineConfig.d.ts +1 -1
- package/dist/config/merge.d.ts +4 -4
- package/dist/config/normalize.d.ts +5 -6
- package/dist/config/normalize.js +2 -2
- package/dist/config/transformLegacyConfig.d.ts +1 -1
- package/dist/config/valid.d.ts +1 -1
- package/dist/constants/build.d.ts +1 -1
- package/dist/constants/color.d.ts +1 -1
- package/dist/constants/dts.d.ts +0 -1
- package/dist/constants/dts.js +0 -3
- package/dist/constants/file.d.ts +1 -1
- package/dist/constants/legacy-preset.d.ts +11 -11
- package/dist/constants/loader.d.ts +1 -1
- package/dist/constants/log.d.ts +1 -1
- package/dist/constants/preset.d.ts +5 -5
- package/dist/debug.d.ts +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/error.d.ts +19 -19
- package/dist/hooks/build.d.ts +17 -17
- package/dist/hooks/dev.d.ts +11 -11
- package/dist/hooks/index.d.ts +29 -28
- package/dist/hooks/misc.d.ts +12 -7
- package/dist/hooks/misc.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/locale/en.d.ts +40 -40
- package/dist/locale/index.d.ts +79 -79
- package/dist/locale/zh.d.ts +40 -40
- package/dist/plugins.d.ts +1 -1
- package/dist/types/color.d.ts +1 -1
- package/dist/types/command.d.ts +9 -9
- package/dist/types/config/copy.d.ts +10 -10
- package/dist/types/config/dev.d.ts +4 -4
- package/dist/types/config/index.d.ts +106 -106
- package/dist/types/config/style.d.ts +37 -37
- package/dist/types/context.d.ts +4 -4
- package/dist/types/dts.d.ts +39 -38
- package/dist/types/esbuild.d.ts +77 -77
- package/dist/types/hooks.d.ts +14 -14
- package/dist/types/index.d.ts +7 -7
- package/dist/types/legacyConfig/index.d.ts +8 -8
- package/dist/types/legacyConfig/output.d.ts +44 -44
- package/dist/types/legacyConfig/source.d.ts +10 -10
- package/dist/types/legacyConfig/tools.d.ts +39 -39
- package/dist/utils/assert.d.ts +1 -1
- package/dist/utils/builder.d.ts +9 -9
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/dts.d.ts +4 -34
- package/dist/utils/dts.js +71 -93
- package/dist/utils/hash.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/input.d.ts +5 -8
- package/dist/utils/log.d.ts +1 -1
- package/dist/utils/map.d.ts +5 -5
- package/dist/utils/onExit.d.ts +1 -1
- package/dist/utils/outExtension.d.ts +6 -6
- package/dist/utils/print.d.ts +3 -3
- package/dist/utils/style.d.ts +7 -7
- package/lib/types.d.ts +0 -1
- package/package.json +18 -24
- package/dist/utils/tspath.d.ts +0 -15
- package/dist/utils/tspath.js +0 -114
|
@@ -2,52 +2,52 @@ import type { JestConfig } from '@modern-js/types';
|
|
|
2
2
|
import type { AcceptedPlugin as PostCSSPlugin } from 'postcss';
|
|
3
3
|
import type { LessConfig, SassConfig } from '../config';
|
|
4
4
|
export type PostCSSOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
to?: string;
|
|
6
|
+
from?: string;
|
|
7
|
+
map?: any;
|
|
8
|
+
syntax?: any;
|
|
9
|
+
parser?: any;
|
|
10
|
+
plugins?: PostCSSPlugin[];
|
|
11
|
+
stringifier?: any;
|
|
12
12
|
};
|
|
13
13
|
export type PostCSSLoaderOptions = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Enable PostCSS Parser support in CSS-in-JS. If you use JS styles the postcss-js parser, add the execute option.
|
|
16
|
+
*/
|
|
17
|
+
execute?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* By default generation of source maps depends on the devtool option. All values enable source map generation except eval and false value.
|
|
20
|
+
*/
|
|
21
|
+
sourceMap?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The special implementation option determines which implementation of PostCSS to use.
|
|
24
|
+
*/
|
|
25
|
+
implementation?: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Allows to set PostCSS options and plugins.
|
|
28
|
+
*/
|
|
29
|
+
postcssOptions?: PostCSSOptions;
|
|
30
30
|
};
|
|
31
31
|
export type PostCSSConfigUtils = {
|
|
32
|
-
|
|
32
|
+
addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
|
|
33
33
|
};
|
|
34
34
|
interface ToolsConfig {
|
|
35
|
-
|
|
35
|
+
speedy?: any | ((config: any) => any);
|
|
36
36
|
}
|
|
37
37
|
export type PostCSSFunction = (options: PostCSSLoaderOptions, utils: PostCSSConfigUtils) => PostCSSLoaderOptions | void;
|
|
38
38
|
export type ToolsLegacyUserConfig = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
babel?: any;
|
|
40
|
+
less?: LessConfig;
|
|
41
|
+
lodash?: any;
|
|
42
|
+
postcss?: PostCSSLoaderOptions | PostCSSFunction;
|
|
43
|
+
sass?: SassConfig;
|
|
44
|
+
speedy?: ToolsConfig['speedy'] | Array<NonNullable<ToolsConfig['speedy']>>;
|
|
45
|
+
/**
|
|
46
|
+
* The configuration of `tools.tailwindcss` is provided by `tailwindcss` plugin.
|
|
47
|
+
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
48
|
+
* @requires `tailwindcss` plugin
|
|
49
|
+
*/
|
|
50
|
+
tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
|
|
51
|
+
jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
|
|
52
52
|
};
|
|
53
|
-
export {};
|
|
53
|
+
export {};
|
package/dist/utils/assert.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export declare function isStyleExt(path: string): boolean;
|
|
|
2
2
|
export declare function isJsExt(path: string): boolean;
|
|
3
3
|
export declare function isJsLoader(loader?: string): boolean;
|
|
4
4
|
export declare function isTsExt(path: string): boolean;
|
|
5
|
-
export declare function isTsLoader(loader?: string): boolean;
|
|
5
|
+
export declare function isTsLoader(loader?: string): boolean;
|
package/dist/utils/builder.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { ExternalHelpers } from '../types/config';
|
|
2
2
|
type Query = Record<string, string | boolean>;
|
|
3
3
|
type ResolveResult = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
originalFilePath: string;
|
|
5
|
+
query: Query;
|
|
6
|
+
rawQuery?: string;
|
|
7
7
|
};
|
|
8
8
|
export declare const getAllDeps: <T>(appDirectory: string, options?: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
dependencies?: boolean;
|
|
10
|
+
devDependencies?: boolean;
|
|
11
|
+
peerDependencies?: boolean;
|
|
12
12
|
}) => Promise<string[]>;
|
|
13
13
|
export declare const checkSwcHelpers: (options: {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
appDirectory: string;
|
|
15
|
+
externalHelpers: ExternalHelpers;
|
|
16
16
|
}) => Promise<void>;
|
|
17
17
|
export declare const normalizeSlashes: (file: string) => string;
|
|
18
18
|
export declare const resolvePathAndQuery: (originalPath: string) => ResolveResult;
|
|
19
|
-
export {};
|
|
19
|
+
export {};
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* transform ['a', 'b'] to { a: undefined, b: undefined }
|
|
3
3
|
*/
|
|
4
4
|
export declare const transformUndefineObject: (arr: string[]) => Record<string, undefined>;
|
|
5
|
-
export declare function mapValue<T = any, U = any>(obj: Record<string, T>, mapper: (x: T) => U): Record<string, U>;
|
|
5
|
+
export declare function mapValue<T = any, U = any>(obj: Record<string, T>, mapper: (x: T) => U): Record<string, U>;
|
package/dist/utils/dts.d.ts
CHANGED
|
@@ -1,39 +1,9 @@
|
|
|
1
1
|
import type { ITsconfig, GeneratorDtsConfig, BuildType, TsTarget } from '../types';
|
|
2
2
|
export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
|
|
3
|
-
export declare const generateDtsInfo: (config: GeneratorDtsConfig) => Promise<{
|
|
4
|
-
userTsconfig: ITsconfig;
|
|
5
|
-
tempTsconfigPath: string;
|
|
6
|
-
tempDistAbsRootPath: string;
|
|
7
|
-
tempDistAbsSrcPath: string;
|
|
8
|
-
}>;
|
|
9
3
|
export declare const getTscBinPath: (appDirectory: string) => Promise<string>;
|
|
10
|
-
export declare const
|
|
11
|
-
userTsconfig: ITsconfig;
|
|
12
|
-
tempTsconfigPath: string;
|
|
13
|
-
tempDistAbsRootPath: string;
|
|
14
|
-
tempDistAbsSrcPath: string;
|
|
15
|
-
}, watchFilenames?: string[]) => Promise<{
|
|
16
|
-
path: string;
|
|
17
|
-
content: string;
|
|
18
|
-
}[]>;
|
|
19
|
-
export declare const writeDtsFiles: (config: GeneratorDtsConfig, options: {
|
|
20
|
-
userTsconfig: ITsconfig;
|
|
21
|
-
tempTsconfigPath: string;
|
|
22
|
-
tempDistAbsRootPath: string;
|
|
23
|
-
tempDistAbsSrcPath: string;
|
|
24
|
-
}, result: {
|
|
25
|
-
path: string;
|
|
26
|
-
content: string;
|
|
27
|
-
}[]) => Promise<void>;
|
|
28
|
-
export declare const addBannerAndFooter: (result: {
|
|
29
|
-
path: string;
|
|
30
|
-
content: string;
|
|
31
|
-
}[], banner?: string, footer?: string) => {
|
|
32
|
-
path: string;
|
|
33
|
-
content: string;
|
|
34
|
-
}[];
|
|
4
|
+
export declare const processDtsFilesAfterTsc: (config: GeneratorDtsConfig) => Promise<void>;
|
|
35
5
|
export declare const printOrThrowDtsErrors: (error: unknown, options: {
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
abortOnError?: boolean;
|
|
7
|
+
buildType: BuildType;
|
|
38
8
|
}) => Promise<void>;
|
|
39
|
-
export declare const tsTargetAtOrAboveES2022: (target: TsTarget) => boolean;
|
|
9
|
+
export declare const tsTargetAtOrAboveES2022: (target: TsTarget) => boolean;
|
package/dist/utils/dts.js
CHANGED
|
@@ -28,69 +28,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var dts_exports = {};
|
|
30
30
|
__export(dts_exports, {
|
|
31
|
-
addBannerAndFooter: () => addBannerAndFooter,
|
|
32
|
-
generateDtsInfo: () => generateDtsInfo,
|
|
33
31
|
getProjectTsconfig: () => getProjectTsconfig,
|
|
34
32
|
getTscBinPath: () => getTscBinPath,
|
|
35
33
|
printOrThrowDtsErrors: () => printOrThrowDtsErrors,
|
|
36
|
-
|
|
37
|
-
tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022
|
|
38
|
-
writeDtsFiles: () => writeDtsFiles
|
|
34
|
+
processDtsFilesAfterTsc: () => processDtsFilesAfterTsc,
|
|
35
|
+
tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022
|
|
39
36
|
});
|
|
40
37
|
module.exports = __toCommonJS(dts_exports);
|
|
41
38
|
var import_path = require("path");
|
|
42
39
|
var import_utils = require("@modern-js/utils");
|
|
43
40
|
var import_magic_string = __toESM(require("magic-string"));
|
|
41
|
+
var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
|
|
42
|
+
var import_napi = require("@ast-grep/napi");
|
|
43
|
+
var import_builder = require("./builder");
|
|
44
44
|
const getProjectTsconfig = async (tsconfigPath) => {
|
|
45
45
|
if (!import_utils.fs.existsSync(tsconfigPath)) {
|
|
46
46
|
return {};
|
|
47
47
|
}
|
|
48
48
|
return import_utils.json5.parse(import_utils.fs.readFileSync(tsconfigPath, "utf-8"));
|
|
49
49
|
};
|
|
50
|
-
const generateDtsInfo = async (config) => {
|
|
51
|
-
var _userTsconfig_references;
|
|
52
|
-
const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;
|
|
53
|
-
const userTsconfig = await getProjectTsconfig(tsconfigPath);
|
|
54
|
-
const { dtsTempDirectory } = await Promise.resolve().then(() => __toESM(require("../constants/dts")));
|
|
55
|
-
const tempDistAbsRootPath = (0, import_path.join)(appDirectory, `${dtsTempDirectory}/${(0, import_utils.nanoid)()}`);
|
|
56
|
-
const tempDistAbsOurDir = (0, import_path.join)(tempDistAbsRootPath, (0, import_path.relative)(appDirectory, absSourceDir));
|
|
57
|
-
const tempTsconfigPath = (0, import_path.join)(tempDistAbsRootPath, (0, import_path.basename)(tsconfigPath));
|
|
58
|
-
import_utils.fs.ensureFileSync(tempTsconfigPath);
|
|
59
|
-
const extendsPath = (0, import_path.join)((0, import_path.relative)((0, import_path.dirname)(tempTsconfigPath), (0, import_path.dirname)(tsconfigPath)), (0, import_path.basename)(tempTsconfigPath));
|
|
60
|
-
const references = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_references = userTsconfig.references) === null || _userTsconfig_references === void 0 ? void 0 : _userTsconfig_references.map((reference) => {
|
|
61
|
-
const { path } = reference;
|
|
62
|
-
if (path) {
|
|
63
|
-
const userTsconfigDir = (0, import_path.dirname)(tsconfigPath);
|
|
64
|
-
const generatedTsconfigDir = (0, import_path.dirname)(tempTsconfigPath);
|
|
65
|
-
return {
|
|
66
|
-
path: (0, import_path.isAbsolute)(path) ? path : (0, import_path.relative)(generatedTsconfigDir, (0, import_path.resolve)(userTsconfigDir, path))
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return reference;
|
|
70
|
-
});
|
|
71
|
-
const resetConfig = {
|
|
72
|
-
extends: extendsPath,
|
|
73
|
-
compilerOptions: {
|
|
74
|
-
// Ensure that .d.ts files are created by tsc, but not .js files
|
|
75
|
-
declaration: true,
|
|
76
|
-
emitDeclarationOnly: true,
|
|
77
|
-
// when `outDir` is './dist', `declarationDir` is `./types`
|
|
78
|
-
// tsc will emit:
|
|
79
|
-
// - ./dist/index.js
|
|
80
|
-
// - ./types/index.d.ts
|
|
81
|
-
// we only want to emit declarations
|
|
82
|
-
declarationDir: tempDistAbsOurDir
|
|
83
|
-
},
|
|
84
|
-
references
|
|
85
|
-
};
|
|
86
|
-
import_utils.fs.writeJSONSync(tempTsconfigPath, resetConfig);
|
|
87
|
-
return {
|
|
88
|
-
userTsconfig,
|
|
89
|
-
tempTsconfigPath,
|
|
90
|
-
tempDistAbsRootPath,
|
|
91
|
-
tempDistAbsSrcPath: tempDistAbsOurDir
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
50
|
const getTscBinPath = async (appDirectory) => {
|
|
95
51
|
const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => __toESM(require("../../compiled/find-up")));
|
|
96
52
|
const tscBinFile = await findUp(async (directory) => {
|
|
@@ -108,58 +64,83 @@ const getTscBinPath = async (appDirectory) => {
|
|
|
108
64
|
}
|
|
109
65
|
return tscBinFile;
|
|
110
66
|
};
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : import_utils.globby.sync(dtsDistPath, {
|
|
117
|
-
absolute: true
|
|
118
|
-
});
|
|
119
|
-
var _userTsconfig_compilerOptions_paths;
|
|
120
|
-
const result = transformDtsAlias({
|
|
121
|
-
filenames: dtsFilenames,
|
|
122
|
-
baseUrl: tempDistAbsRootPath,
|
|
123
|
-
paths: (_userTsconfig_compilerOptions_paths = (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.paths) !== null && _userTsconfig_compilerOptions_paths !== void 0 ? _userTsconfig_compilerOptions_paths : {}
|
|
67
|
+
const processDtsFilesAfterTsc = async (config) => {
|
|
68
|
+
const { distPath, tsconfigPath, userTsconfig, dtsExtension, banner, footer } = config;
|
|
69
|
+
const dtsFilesPath = await (0, import_utils.globby)("**/*.d.ts", {
|
|
70
|
+
absolute: true,
|
|
71
|
+
cwd: distPath
|
|
124
72
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
73
|
+
const result = (0, import_tsconfig_paths.loadConfig)(tsconfigPath);
|
|
74
|
+
if (result.resultType === "failed") {
|
|
75
|
+
import_utils.logger.error(result.message);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
|
|
79
|
+
const matchPath = (0, import_tsconfig_paths.createMatchPath)(absoluteBaseUrl, paths, mainFields, addMatchAll);
|
|
80
|
+
const Pattern = [
|
|
81
|
+
`import $VAR from '$MATCH'`,
|
|
82
|
+
`import $VAR from "$MATCH"`,
|
|
83
|
+
`export {$$$VAR} from '$MATCH'`,
|
|
84
|
+
`export {$$$VAR} from "$MATCH"`,
|
|
85
|
+
`export * from '$MATCH'`,
|
|
86
|
+
`export * from "$MATCH"`,
|
|
87
|
+
`export * as $VAR from '$MATCH'`,
|
|
88
|
+
`export * as $VAR from "$MATCH"`,
|
|
89
|
+
`import('$MATCH')`,
|
|
90
|
+
`import("$MATCH")`
|
|
91
|
+
];
|
|
92
|
+
await Promise.all(dtsFilesPath.map((filePath) => {
|
|
93
|
+
var _userTsconfig_compilerOptions;
|
|
94
|
+
const code = import_utils.fs.readFileSync(filePath, "utf8");
|
|
95
|
+
let matchModule = [];
|
|
96
|
+
try {
|
|
97
|
+
const sgNode = import_napi.ts.parse(code).root();
|
|
98
|
+
matchModule = Pattern.map((p) => sgNode.findAll(p)).flat().map((node) => {
|
|
99
|
+
const matchNode = node.getMatch("MATCH");
|
|
100
|
+
return {
|
|
101
|
+
name: matchNode.text(),
|
|
102
|
+
start: matchNode.range().start.index,
|
|
103
|
+
end: matchNode.range().end.index
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
} catch (e) {
|
|
107
|
+
import_utils.logger.error("[parse error]", e);
|
|
108
|
+
}
|
|
109
|
+
const str = new import_magic_string.default(code);
|
|
110
|
+
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));
|
|
111
|
+
matchModule.forEach((module2) => {
|
|
112
|
+
if (!module2.name) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const { start, end, name } = module2;
|
|
116
|
+
const absoluteImportPath = matchPath(name);
|
|
117
|
+
if (absoluteImportPath) {
|
|
118
|
+
const relativePath = (0, import_path.relative)((0, import_path.dirname)(originalFilePath), absoluteImportPath);
|
|
119
|
+
const relativeImportPath = (0, import_builder.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
|
|
120
|
+
str.overwrite(start, end, relativeImportPath);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
banner && str.prepend(`${banner}
|
|
124
|
+
`);
|
|
125
|
+
footer && str.append(`
|
|
126
|
+
${footer}
|
|
127
|
+
`);
|
|
128
|
+
const content = str.toString();
|
|
129
|
+
const finalPath = (
|
|
134
130
|
// We confirm that users will not mix ts and c(m)ts files in their projects.
|
|
135
131
|
// If a mix is required, please configure separate buildConfig to handle different inputs.
|
|
136
132
|
// So we don't replace .d.(c|m)ts that generated by tsc directly, this can confirm that
|
|
137
133
|
// users can use c(m)ts directly rather than enable autoExtension, in this condition,
|
|
138
134
|
// users need to set esbuild out-extensions like { '.js': '.mjs' }
|
|
139
|
-
|
|
135
|
+
filePath.replace(/\.d\.ts/, dtsExtension)
|
|
140
136
|
);
|
|
141
|
-
import_utils.fs.ensureFileSync(filepath);
|
|
142
137
|
return import_utils.fs.writeFile(
|
|
143
138
|
// only replace .d.ts, if tsc generate .d.m(c)ts, keep.
|
|
144
|
-
|
|
139
|
+
finalPath,
|
|
145
140
|
content
|
|
146
141
|
);
|
|
147
142
|
}));
|
|
148
143
|
};
|
|
149
|
-
const addBannerAndFooter = (result, banner, footer) => {
|
|
150
|
-
return result.map(({ path, content }) => {
|
|
151
|
-
const ms = new import_magic_string.default(content);
|
|
152
|
-
banner && ms.prepend(`${banner}
|
|
153
|
-
`);
|
|
154
|
-
footer && ms.append(`
|
|
155
|
-
${footer}
|
|
156
|
-
`);
|
|
157
|
-
return {
|
|
158
|
-
path,
|
|
159
|
-
content: ms.toString()
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
144
|
const printOrThrowDtsErrors = async (error, options) => {
|
|
164
145
|
const { InternalDTSError } = await Promise.resolve().then(() => __toESM(require("../error")));
|
|
165
146
|
const local = await Promise.resolve().then(() => __toESM(require("../locale")));
|
|
@@ -180,12 +161,9 @@ const printOrThrowDtsErrors = async (error, options) => {
|
|
|
180
161
|
const tsTargetAtOrAboveES2022 = (target) => target === "es2022" || target === "esnext";
|
|
181
162
|
// Annotate the CommonJS export names for ESM import in node:
|
|
182
163
|
0 && (module.exports = {
|
|
183
|
-
addBannerAndFooter,
|
|
184
|
-
generateDtsInfo,
|
|
185
164
|
getProjectTsconfig,
|
|
186
165
|
getTscBinPath,
|
|
187
166
|
printOrThrowDtsErrors,
|
|
188
|
-
|
|
189
|
-
tsTargetAtOrAboveES2022
|
|
190
|
-
writeDtsFiles
|
|
167
|
+
processDtsFilesAfterTsc,
|
|
168
|
+
tsTargetAtOrAboveES2022
|
|
191
169
|
});
|
package/dist/utils/hash.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export declare function getHash(content: Buffer | string, encoding: any, type?: string): string;
|
|
2
|
+
export declare function getHash(content: Buffer | string, encoding: any, type?: string): string;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -25,7 +25,6 @@ __reExport(utils_exports, require("./log"), module.exports);
|
|
|
25
25
|
__reExport(utils_exports, require("./map"), module.exports);
|
|
26
26
|
__reExport(utils_exports, require("./print"), module.exports);
|
|
27
27
|
__reExport(utils_exports, require("./style"), module.exports);
|
|
28
|
-
__reExport(utils_exports, require("./tspath"), module.exports);
|
|
29
28
|
__reExport(utils_exports, require("./outExtension"), module.exports);
|
|
30
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
30
|
0 && (module.exports = {
|
|
@@ -39,6 +38,5 @@ __reExport(utils_exports, require("./outExtension"), module.exports);
|
|
|
39
38
|
...require("./map"),
|
|
40
39
|
...require("./print"),
|
|
41
40
|
...require("./style"),
|
|
42
|
-
...require("./tspath"),
|
|
43
41
|
...require("./outExtension")
|
|
44
42
|
});
|
package/dist/utils/input.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Input } from '../types';
|
|
2
|
-
export declare const getDefaultIndexEntry: ({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}: {
|
|
6
|
-
isTsProject: boolean;
|
|
7
|
-
appDirectory: string;
|
|
2
|
+
export declare const getDefaultIndexEntry: ({ isTsProject, appDirectory, }: {
|
|
3
|
+
isTsProject: boolean;
|
|
4
|
+
appDirectory: string;
|
|
8
5
|
}) => Promise<string[]>;
|
|
9
6
|
export declare const normalizeInput: (input: Input, appDirectory: string, enableSvgr: boolean) => Promise<string[] | {
|
|
10
|
-
|
|
11
|
-
}>;
|
|
7
|
+
[name: string]: string;
|
|
8
|
+
}>;
|
package/dist/utils/log.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const withLogTitle: (titleText: string, message: string) => string;
|
|
1
|
+
export declare const withLogTitle: (titleText: string, message: string) => string;
|
package/dist/utils/map.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { RawSourceMap } from '@ampproject/remapping/dist/types/types';
|
|
2
2
|
import type { SourceMap } from '../types';
|
|
3
3
|
interface Options {
|
|
4
|
-
|
|
4
|
+
needSourceMap: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare function normalizeSourceMap(map: string | RawSourceMap | undefined, opts?: Options): SourceMap | undefined;
|
|
7
7
|
export type MergeMapResult = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
toString: () => string;
|
|
9
|
+
toMap: () => SourceMap;
|
|
10
|
+
toComment: () => string;
|
|
11
11
|
};
|
|
12
12
|
export declare function mergeMaps(mapList: SourceMap[]): MergeMapResult;
|
|
13
|
-
export {};
|
|
13
|
+
export {};
|
package/dist/utils/onExit.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const addExitListener: (fn: () => Promise<void>) => Promise<void>;
|
|
1
|
+
export declare const addExitListener: (fn: () => Promise<void>) => Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Format } from '../types';
|
|
2
2
|
export declare const getDefaultOutExtension: (options: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
format: Format;
|
|
4
|
+
root: string;
|
|
5
|
+
autoExtension: boolean;
|
|
6
6
|
}) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
7
|
+
jsExtension: string;
|
|
8
|
+
dtsExtension: string;
|
|
9
|
+
};
|
package/dist/utils/print.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { RollupOutput } from '../../compiled/rollup/types/rollup';
|
|
2
2
|
import { Chunk } from '../types';
|
|
3
3
|
type Files = {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
name: string;
|
|
5
|
+
size: number;
|
|
6
6
|
};
|
|
7
7
|
export declare const bundleFiles: Files[];
|
|
8
8
|
export declare const bundlelessFiles: Files[];
|
|
@@ -11,4 +11,4 @@ export declare const addRollupChunk: (rollupOutput: RollupOutput, appDirectory:
|
|
|
11
11
|
export declare const addDtsFiles: (distDir: string, appDirectory: string) => Promise<void>;
|
|
12
12
|
export declare const printFileSize: () => void;
|
|
13
13
|
export declare const printSucceed: (totalDuration: number) => void;
|
|
14
|
-
export {};
|
|
14
|
+
export {};
|
package/dist/utils/style.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import type { PartialBaseBuildConfig, PostcssOptions, LessOptions, SassOptions }
|
|
|
2
2
|
export declare const getLessConfig: (config: PartialBaseBuildConfig) => Promise<LessOptions>;
|
|
3
3
|
export declare const getSassConfig: (config: PartialBaseBuildConfig) => Promise<SassOptions>;
|
|
4
4
|
export declare const getPostcssConfig: (config: PartialBaseBuildConfig) => Promise<PostcssOptions & {
|
|
5
|
-
|
|
5
|
+
$$tools?: string | undefined;
|
|
6
6
|
}>;
|
|
7
7
|
export declare const getStyleConfig: (config: PartialBaseBuildConfig) => Promise<{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}>;
|
|
8
|
+
less: LessOptions;
|
|
9
|
+
sass: SassOptions;
|
|
10
|
+
postcss: PostcssOptions & {
|
|
11
|
+
$$tools?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.42.0",
|
|
4
4
|
"description": "Simple, powerful, high-performance modern npm package development solution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modern",
|
|
@@ -48,20 +48,16 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@ampproject/remapping": "1.0.2",
|
|
50
50
|
"@ast-grep/napi": "0.12.0",
|
|
51
|
-
"@
|
|
52
|
-
"@babel/parser": "^7.22.15",
|
|
53
|
-
"@babel/traverse": "7.23.2",
|
|
54
|
-
"@babel/types": "^7.22.15",
|
|
55
|
-
"@modern-js/swc-plugins": "0.6.4",
|
|
51
|
+
"@modern-js/swc-plugins": "0.6.5",
|
|
56
52
|
"@rollup/pluginutils": "4.1.1",
|
|
57
53
|
"@svgr/core": "8.0.0",
|
|
58
54
|
"@svgr/plugin-jsx": "8.0.1",
|
|
59
55
|
"@svgr/plugin-svgo": "8.0.1",
|
|
60
|
-
"@swc/helpers": "0.5.
|
|
56
|
+
"@swc/helpers": "0.5.3",
|
|
61
57
|
"convert-source-map": "1.8.0",
|
|
62
|
-
"enhanced-resolve": "5.
|
|
58
|
+
"enhanced-resolve": "5.12.0",
|
|
63
59
|
"esbuild": "0.19.2",
|
|
64
|
-
"magic-string": "0.
|
|
60
|
+
"magic-string": "0.30.5",
|
|
65
61
|
"postcss": "8.4.31",
|
|
66
62
|
"postcss-modules": "4.3.0",
|
|
67
63
|
"safe-identifier": "0.4.2",
|
|
@@ -71,26 +67,24 @@
|
|
|
71
67
|
"tapable": "2.2.1",
|
|
72
68
|
"terser": "5.19.2",
|
|
73
69
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
74
|
-
"@modern-js/core": "2.
|
|
75
|
-
"@modern-js/
|
|
76
|
-
"@modern-js/plugin": "2.
|
|
77
|
-
"@modern-js/plugin-
|
|
78
|
-
"@modern-js/
|
|
79
|
-
"@modern-js/plugin-lint": "2.
|
|
80
|
-
"@modern-js/
|
|
81
|
-
"@modern-js/
|
|
82
|
-
"@modern-js/
|
|
70
|
+
"@modern-js/core": "2.42.0",
|
|
71
|
+
"@modern-js/plugin-changeset": "2.42.0",
|
|
72
|
+
"@modern-js/plugin": "2.42.0",
|
|
73
|
+
"@modern-js/plugin-i18n": "2.42.0",
|
|
74
|
+
"@modern-js/new-action": "2.42.0",
|
|
75
|
+
"@modern-js/plugin-lint": "2.42.0",
|
|
76
|
+
"@modern-js/upgrade": "2.42.0",
|
|
77
|
+
"@modern-js/utils": "2.42.0",
|
|
78
|
+
"@modern-js/types": "2.42.0"
|
|
83
79
|
},
|
|
84
80
|
"devDependencies": {
|
|
85
|
-
"@types/babel__generator": "7.6.4",
|
|
86
|
-
"@types/babel__traverse": "7.18.5",
|
|
87
81
|
"@types/convert-source-map": "1.5.2",
|
|
88
82
|
"@types/node": "^14",
|
|
89
83
|
"typescript": "^5",
|
|
90
|
-
"@modern-js/builder-webpack-provider": "2.
|
|
91
|
-
"@modern-js/self": "npm:@modern-js/module-tools@2.
|
|
92
|
-
"@scripts/build": "2.
|
|
93
|
-
"@scripts/vitest-config": "2.
|
|
84
|
+
"@modern-js/builder-webpack-provider": "2.42.0",
|
|
85
|
+
"@modern-js/self": "npm:@modern-js/module-tools@2.42.0",
|
|
86
|
+
"@scripts/build": "2.42.0",
|
|
87
|
+
"@scripts/vitest-config": "2.42.0"
|
|
94
88
|
},
|
|
95
89
|
"peerDependencies": {
|
|
96
90
|
"typescript": "^4 || ^5"
|
package/dist/utils/tspath.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface TransformOption {
|
|
2
|
-
filename: string;
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
paths: Record<string, string[] | string>;
|
|
5
|
-
}
|
|
6
|
-
interface TransformDtsAliasOption {
|
|
7
|
-
filenames?: string[];
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
paths: Record<string, string[] | string>;
|
|
10
|
-
}
|
|
11
|
-
export declare const transformDtsAlias: (option: TransformDtsAliasOption) => {
|
|
12
|
-
path: string;
|
|
13
|
-
content: string;
|
|
14
|
-
}[];
|
|
15
|
-
export {};
|