@modern-js/module-tools 0.0.0-nightly-20231204170637 → 0.0.0-nightly-20231206170639

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.
Files changed (93) hide show
  1. package/dist/build.d.ts +1 -1
  2. package/dist/builder/build.d.ts +7 -7
  3. package/dist/builder/clear.d.ts +1 -1
  4. package/dist/builder/copy.d.ts +9 -9
  5. package/dist/builder/dts/index.d.ts +1 -1
  6. package/dist/builder/dts/rollup.d.ts +1 -13
  7. package/dist/builder/dts/tsc.d.ts +1 -1
  8. package/dist/builder/dts/tsc.js +2 -6
  9. package/dist/builder/esbuild/adapter.d.ts +1 -1
  10. package/dist/builder/esbuild/hook.d.ts +1 -1
  11. package/dist/builder/esbuild/index.d.ts +28 -28
  12. package/dist/builder/esbuild/resolve.d.ts +9 -9
  13. package/dist/builder/esbuild/sourcemap.d.ts +14 -14
  14. package/dist/builder/esbuild/transform.d.ts +4 -4
  15. package/dist/builder/esbuild/watch.d.ts +1 -1
  16. package/dist/builder/esbuild/write-file.d.ts +1 -1
  17. package/dist/builder/feature/asset.d.ts +5 -5
  18. package/dist/builder/feature/format-cjs.d.ts +3 -3
  19. package/dist/builder/feature/index.d.ts +1 -1
  20. package/dist/builder/feature/json.d.ts +3 -3
  21. package/dist/builder/feature/redirect.d.ts +3 -3
  22. package/dist/builder/feature/style/index.d.ts +3 -3
  23. package/dist/builder/feature/style/lessAliasPlugin.d.ts +7 -7
  24. package/dist/builder/feature/style/lessRender.d.ts +1 -1
  25. package/dist/builder/feature/style/postcssTransformer.d.ts +3 -3
  26. package/dist/builder/feature/style/postcssUrlPlugin.d.ts +3 -3
  27. package/dist/builder/feature/style/sassRender.d.ts +1 -1
  28. package/dist/builder/feature/style/transformStyle.d.ts +7 -7
  29. package/dist/builder/feature/style/utils.d.ts +3 -3
  30. package/dist/builder/feature/swc.d.ts +5 -5
  31. package/dist/builder/feature/terser.d.ts +3 -3
  32. package/dist/builder/index.d.ts +4 -4
  33. package/dist/builder/platform.d.ts +1 -1
  34. package/dist/cli.d.ts +1 -1
  35. package/dist/command.d.ts +1 -1
  36. package/dist/config/defineConfig.d.ts +1 -1
  37. package/dist/config/merge.d.ts +4 -4
  38. package/dist/config/normalize.d.ts +3 -3
  39. package/dist/config/transformLegacyConfig.d.ts +1 -1
  40. package/dist/config/valid.d.ts +1 -1
  41. package/dist/constants/build.d.ts +1 -1
  42. package/dist/constants/color.d.ts +1 -1
  43. package/dist/constants/dts.d.ts +1 -1
  44. package/dist/constants/file.d.ts +1 -1
  45. package/dist/constants/legacy-preset.d.ts +11 -11
  46. package/dist/constants/loader.d.ts +1 -1
  47. package/dist/constants/log.d.ts +1 -1
  48. package/dist/constants/preset.d.ts +5 -5
  49. package/dist/debug.d.ts +1 -1
  50. package/dist/dev.d.ts +1 -1
  51. package/dist/error.d.ts +19 -19
  52. package/dist/hooks/build.d.ts +16 -16
  53. package/dist/hooks/dev.d.ts +11 -11
  54. package/dist/hooks/index.d.ts +29 -29
  55. package/dist/hooks/misc.d.ts +11 -11
  56. package/dist/index.d.ts +1 -1
  57. package/dist/locale/en.d.ts +40 -40
  58. package/dist/locale/index.d.ts +79 -79
  59. package/dist/locale/zh.d.ts +40 -40
  60. package/dist/plugins.d.ts +1 -1
  61. package/dist/types/color.d.ts +1 -1
  62. package/dist/types/command.d.ts +9 -9
  63. package/dist/types/config/copy.d.ts +10 -10
  64. package/dist/types/config/dev.d.ts +4 -4
  65. package/dist/types/config/index.d.ts +106 -106
  66. package/dist/types/config/style.d.ts +37 -37
  67. package/dist/types/context.d.ts +4 -4
  68. package/dist/types/dts.d.ts +39 -39
  69. package/dist/types/esbuild.d.ts +77 -77
  70. package/dist/types/hooks.d.ts +14 -14
  71. package/dist/types/index.d.ts +7 -7
  72. package/dist/types/legacyConfig/index.d.ts +8 -8
  73. package/dist/types/legacyConfig/output.d.ts +44 -44
  74. package/dist/types/legacyConfig/source.d.ts +10 -10
  75. package/dist/types/legacyConfig/tools.d.ts +39 -39
  76. package/dist/utils/assert.d.ts +1 -1
  77. package/dist/utils/builder.d.ts +9 -9
  78. package/dist/utils/common.d.ts +1 -1
  79. package/dist/utils/dts.d.ts +4 -18
  80. package/dist/utils/dts.js +69 -44
  81. package/dist/utils/hash.d.ts +1 -1
  82. package/dist/utils/index.d.ts +1 -2
  83. package/dist/utils/index.js +0 -2
  84. package/dist/utils/input.d.ts +5 -8
  85. package/dist/utils/log.d.ts +1 -1
  86. package/dist/utils/map.d.ts +5 -5
  87. package/dist/utils/onExit.d.ts +1 -1
  88. package/dist/utils/outExtension.d.ts +6 -6
  89. package/dist/utils/print.d.ts +3 -3
  90. package/dist/utils/style.d.ts +7 -7
  91. package/package.json +14 -20
  92. package/dist/utils/tspath.d.ts +0 -15
  93. package/dist/utils/tspath.js +0 -114
@@ -3,29 +3,29 @@ import { registerHook } from '../hooks';
3
3
  import type { BaseBuildConfig, BuildConfig, BuildType } from './config';
4
4
  import type { DevCommandOptions, BuildCommandOptions } from './command';
5
5
  export interface BuildTaskResult {
6
- status: 'success' | 'fail';
7
- message?: string;
8
- config: BaseBuildConfig;
6
+ status: 'success' | 'fail';
7
+ message?: string;
8
+ config: BaseBuildConfig;
9
9
  }
10
10
  export interface BuildResult {
11
- status: 'success' | 'fail';
12
- message?: string;
13
- config: BuildConfig;
14
- commandOptions: BuildCommandOptions;
15
- totalDuration: number;
11
+ status: 'success' | 'fail';
12
+ message?: string;
13
+ config: BuildConfig;
14
+ commandOptions: BuildCommandOptions;
15
+ totalDuration: number;
16
16
  }
17
17
  export interface BuildPlatformResult {
18
- status: 'success' | 'fail';
19
- message: string | Error | null;
18
+ status: 'success' | 'fail';
19
+ message: string | Error | null;
20
20
  }
21
21
  export type DevToolData = BaseDevToolData<DevCommandOptions>;
22
22
  export type PromptResult = {
23
- choiceDevTool: string;
23
+ choiceDevTool: string;
24
24
  } & Record<string, any>;
25
25
  export type ModuleToolsHooks = typeof registerHook;
26
26
  export interface WatchJsHookContext {
27
- buildConfig: BaseBuildConfig;
27
+ buildConfig: BaseBuildConfig;
28
28
  }
29
29
  export interface WatchDtsHookContext {
30
- buildType: BuildType;
31
- }
30
+ buildType: BuildType;
31
+ }
@@ -11,17 +11,17 @@ export * from './context';
11
11
  export * from './esbuild';
12
12
  export type { CliPlugin, IAppContext, PluginAPI } from '@modern-js/core';
13
13
  export type ModuleTools = {
14
- hooks: ModuleToolsHooks;
15
- userConfig: ModuleExtraConfig;
16
- normalizedConfig: Required<ModuleExtraConfig>;
14
+ hooks: ModuleToolsHooks;
15
+ userConfig: ModuleExtraConfig;
16
+ normalizedConfig: Required<ModuleExtraConfig>;
17
17
  };
18
18
  export type LegacyModuleTools = {
19
- hooks: ModuleToolsHooks;
20
- userConfig: ModuleToolsLegacyUserConfig;
21
- normalizedConfig: ModuleToolsLegacyNormalizedConfig;
19
+ hooks: ModuleToolsHooks;
20
+ userConfig: ModuleToolsLegacyUserConfig;
21
+ normalizedConfig: ModuleToolsLegacyNormalizedConfig;
22
22
  };
23
23
  export type ModuleUserConfig = UserConfig<ModuleTools>;
24
24
  export type ModuleLegacyUserConfig = UserConfig<LegacyModuleTools>;
25
25
  export type ModuleNormalizedConfig = NormalizedConfig<ModuleTools>;
26
26
  export type ModuleLegacyNormalizedConfig = NormalizedConfig<LegacyModuleTools>;
27
- export type ModuleConfigParams = ModuleUserConfig | Promise<ModuleUserConfig> | ((env: any) => ModuleUserConfig | Promise<ModuleUserConfig>);
27
+ export type ModuleConfigParams = ModuleUserConfig | Promise<ModuleUserConfig> | ((env: any) => ModuleUserConfig | Promise<ModuleUserConfig>);
@@ -5,16 +5,16 @@ export type { OutputLegacyUserConfig } from './output';
5
5
  export type { SourceLegacyUserConfig } from './source';
6
6
  export type { ToolsLegacyUserConfig } from './tools';
7
7
  export interface RuntimeLegacyConfig {
8
- [name: string]: any;
8
+ [name: string]: any;
9
9
  }
10
10
  export interface RuntimeByEntriesLegacyConfig {
11
- [name: string]: RuntimeLegacyConfig;
11
+ [name: string]: RuntimeLegacyConfig;
12
12
  }
13
13
  export type ModuleToolsLegacyUserConfig = {
14
- source?: SourceLegacyUserConfig;
15
- output?: OutputLegacyUserConfig;
16
- tools?: ToolsLegacyUserConfig;
17
- runtime?: RuntimeLegacyConfig;
18
- legacy?: boolean;
14
+ source?: SourceLegacyUserConfig;
15
+ output?: OutputLegacyUserConfig;
16
+ tools?: ToolsLegacyUserConfig;
17
+ runtime?: RuntimeLegacyConfig;
18
+ legacy?: boolean;
19
19
  };
20
- export type ModuleToolsLegacyNormalizedConfig = Required<ModuleToolsLegacyUserConfig>;
20
+ export type ModuleToolsLegacyNormalizedConfig = Required<ModuleToolsLegacyUserConfig>;
@@ -5,57 +5,57 @@ export type LegacyTarget = 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2
5
5
  export type LegacyBuildType = 'bundle' | 'bundleless';
6
6
  export type LegacySourceMap = boolean | 'inline' | 'external';
7
7
  export type LegacyBundleOptions = {
8
- entry?: Record<string, string>;
9
- platform?: Platform;
10
- splitting?: boolean;
11
- minify?: Minify;
12
- externals?: Externals;
13
- skipDeps?: boolean;
14
- getModuleId?: (moduleName: string) => string | undefined;
8
+ entry?: Record<string, string>;
9
+ platform?: Platform;
10
+ splitting?: boolean;
11
+ minify?: Minify;
12
+ externals?: Externals;
13
+ skipDeps?: boolean;
14
+ getModuleId?: (moduleName: string) => string | undefined;
15
15
  };
16
16
  export type LegacyBundlelessOptions = {
17
- sourceDir?: string;
18
- style?: {
19
- compileMode?: 'all' | 'only-compiled-code' | /* may be will be deprecated */'only-source-code' | false;
20
- path?: string;
21
- };
22
- static?: {
23
- path?: string;
24
- };
17
+ sourceDir?: string;
18
+ style?: {
19
+ compileMode?: 'all' | 'only-compiled-code' | /* may be will be deprecated */ 'only-source-code' | false;
20
+ path?: string;
21
+ };
22
+ static?: {
23
+ path?: string;
24
+ };
25
25
  };
26
26
  export type LegacyBaseBuildConfig = {
27
- format?: LegacyFormat;
28
- target?: LegacyTarget;
29
- sourceMap?: LegacySourceMap;
30
- buildType?: LegacyBuildType;
31
- bundleOptions?: LegacyBundleOptions;
32
- bundlelessOptions?: LegacyBundlelessOptions;
33
- tsconfig?: string;
34
- enableDts?: boolean;
35
- dtsOnly?: boolean;
36
- outputPath?: string;
27
+ format?: LegacyFormat;
28
+ target?: LegacyTarget;
29
+ sourceMap?: LegacySourceMap;
30
+ buildType?: LegacyBuildType;
31
+ bundleOptions?: LegacyBundleOptions;
32
+ bundlelessOptions?: LegacyBundlelessOptions;
33
+ tsconfig?: string;
34
+ enableDts?: boolean;
35
+ dtsOnly?: boolean;
36
+ outputPath?: string;
37
37
  };
38
38
  export type LegacyBuildConfig = LegacyBaseBuildConfig | LegacyBaseBuildConfig[];
39
39
  export type JsSyntaxType = 'CJS+ES6' | 'ESM+ES5' | 'ESM+ES6';
40
40
  export interface PackageFields {
41
- main?: JsSyntaxType;
42
- 'jsnext:modern'?: JsSyntaxType;
43
- module?: JsSyntaxType;
41
+ main?: JsSyntaxType;
42
+ 'jsnext:modern'?: JsSyntaxType;
43
+ module?: JsSyntaxType;
44
44
  }
45
45
  export type OutputLegacyUserConfig = {
46
- jsPath?: string;
47
- path?: string;
48
- copy?: Array<Record<string, unknown> & {
49
- from: string;
50
- }>;
51
- disableTsChecker?: boolean;
52
- /** @deprecated Use the `buildConfig.bundlelessOptions.static.path` instead . */
53
- assetsPath?: string;
54
- /** @deprecated Use the `buildConfig.sourceMap` instead */
55
- disableSourceMap?: boolean;
56
- buildPreset?: LegacyBuildPreset;
57
- buildConfig?: LegacyBuildConfig;
58
- importStyle?: 'source-code' | 'compiled-code';
59
- packageMode?: 'universal-js' | 'universal-js-lite' | 'browser-js' | 'browser-js-lite' | 'node-js';
60
- packageFields?: PackageFields;
61
- };
46
+ jsPath?: string;
47
+ path?: string;
48
+ copy?: Array<Record<string, unknown> & {
49
+ from: string;
50
+ }>;
51
+ disableTsChecker?: boolean;
52
+ /** @deprecated Use the `buildConfig.bundlelessOptions.static.path` instead . */
53
+ assetsPath?: string;
54
+ /** @deprecated Use the `buildConfig.sourceMap` instead */
55
+ disableSourceMap?: boolean;
56
+ buildPreset?: LegacyBuildPreset;
57
+ buildConfig?: LegacyBuildConfig;
58
+ importStyle?: 'source-code' | 'compiled-code';
59
+ packageMode?: 'universal-js' | 'universal-js-lite' | 'browser-js' | 'browser-js-lite' | 'node-js';
60
+ packageFields?: PackageFields;
61
+ };
@@ -1,12 +1,12 @@
1
1
  import type { AliasOption } from '../config';
2
2
  export type SourceLegacyUserConfig = {
3
- alias?: AliasOption;
4
- envVars?: Array<string>;
5
- globalVars?: Record<string, string>;
6
- jsxTransformRuntime?: 'automatic' | 'classic';
7
- /**
8
- * @deprecated designSystem is no longer required.
9
- * If you are using Tailwind CSS, you can now use the `theme` option of Tailwind CSS, they are the same.
10
- */
11
- designSystem?: Record<string, any>;
12
- };
3
+ alias?: AliasOption;
4
+ envVars?: Array<string>;
5
+ globalVars?: Record<string, string>;
6
+ jsxTransformRuntime?: 'automatic' | 'classic';
7
+ /**
8
+ * @deprecated designSystem is no longer required.
9
+ * If you are using Tailwind CSS, you can now use the `theme` option of Tailwind CSS, they are the same.
10
+ */
11
+ designSystem?: Record<string, any>;
12
+ };
@@ -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
- to?: string;
6
- from?: string;
7
- map?: any;
8
- syntax?: any;
9
- parser?: any;
10
- plugins?: PostCSSPlugin[];
11
- stringifier?: any;
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
- * 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;
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
- addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
32
+ addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
33
33
  };
34
34
  interface ToolsConfig {
35
- speedy?: any | ((config: any) => any);
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
- 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);
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 {};
@@ -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;
@@ -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
- originalFilePath: string;
5
- query: Query;
6
- rawQuery?: string;
4
+ originalFilePath: string;
5
+ query: Query;
6
+ rawQuery?: string;
7
7
  };
8
8
  export declare const getAllDeps: <T>(appDirectory: string, options?: {
9
- dependencies?: boolean;
10
- devDependencies?: boolean;
11
- peerDependencies?: boolean;
9
+ dependencies?: boolean;
10
+ devDependencies?: boolean;
11
+ peerDependencies?: boolean;
12
12
  }) => Promise<string[]>;
13
13
  export declare const checkSwcHelpers: (options: {
14
- appDirectory: string;
15
- externalHelpers: ExternalHelpers;
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 {};
@@ -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>;
@@ -1,23 +1,9 @@
1
1
  import type { ITsconfig, GeneratorDtsConfig, BuildType, TsTarget } from '../types';
2
2
  export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
3
3
  export declare const getTscBinPath: (appDirectory: string) => Promise<string>;
4
- export declare const resolveAlias: (config: GeneratorDtsConfig) => Promise<{
5
- path: string;
6
- content: string;
7
- }[]>;
8
- export declare const writeDtsFiles: (config: GeneratorDtsConfig, result: {
9
- path: string;
10
- content: string;
11
- }[]) => Promise<void>;
12
- export declare const addBannerAndFooter: (result: {
13
- path: string;
14
- content: string;
15
- }[], banner?: string, footer?: string) => {
16
- path: string;
17
- content: string;
18
- }[];
4
+ export declare const processDtsFilesAfterTsc: (config: GeneratorDtsConfig) => Promise<void>;
19
5
  export declare const printOrThrowDtsErrors: (error: unknown, options: {
20
- abortOnError?: boolean;
21
- buildType: BuildType;
6
+ abortOnError?: boolean;
7
+ buildType: BuildType;
22
8
  }) => Promise<void>;
23
- export declare const tsTargetAtOrAboveES2022: (target: TsTarget) => boolean;
9
+ export declare const tsTargetAtOrAboveES2022: (target: TsTarget) => boolean;
package/dist/utils/dts.js CHANGED
@@ -28,18 +28,19 @@ 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
31
  getProjectTsconfig: () => getProjectTsconfig,
33
32
  getTscBinPath: () => getTscBinPath,
34
33
  printOrThrowDtsErrors: () => printOrThrowDtsErrors,
35
- resolveAlias: () => resolveAlias,
36
- tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022,
37
- writeDtsFiles: () => writeDtsFiles
34
+ processDtsFilesAfterTsc: () => processDtsFilesAfterTsc,
35
+ tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022
38
36
  });
39
37
  module.exports = __toCommonJS(dts_exports);
40
38
  var import_path = require("path");
41
39
  var import_utils = require("@modern-js/utils");
42
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");
43
44
  const getProjectTsconfig = async (tsconfigPath) => {
44
45
  if (!import_utils.fs.existsSync(tsconfigPath)) {
45
46
  return {};
@@ -63,57 +64,83 @@ const getTscBinPath = async (appDirectory) => {
63
64
  }
64
65
  return tscBinFile;
65
66
  };
66
- const resolveAlias = async (config) => {
67
- var _userTsconfig_compilerOptions, _userTsconfig_compilerOptions1;
68
- const { userTsconfig, distPath, tsconfigPath } = config;
69
- const { transformDtsAlias } = await Promise.resolve().then(() => __toESM(require("./tspath")));
70
- const dtsFilenames = await (0, import_utils.globby)("**/*.d.ts", {
67
+ const processDtsFilesAfterTsc = async (config) => {
68
+ const { distPath, tsconfigPath, userTsconfig, dtsExtension, banner, footer } = config;
69
+ const dtsFilesPath = await (0, import_utils.globby)("**/*.d.ts", {
71
70
  absolute: true,
72
71
  cwd: distPath
73
72
  });
74
- const userBaseUrl = (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.baseUrl;
75
- const baseUrl = (0, import_path.isAbsolute)(userBaseUrl || ".") ? userBaseUrl : (0, import_path.join)((0, import_path.dirname)(tsconfigPath), userBaseUrl || ".");
76
- var _userTsconfig_compilerOptions_paths;
77
- const result = transformDtsAlias({
78
- filenames: dtsFilenames,
79
- baseUrl,
80
- paths: (_userTsconfig_compilerOptions_paths = (_userTsconfig_compilerOptions1 = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions1 === void 0 ? void 0 : _userTsconfig_compilerOptions1.paths) !== null && _userTsconfig_compilerOptions_paths !== void 0 ? _userTsconfig_compilerOptions_paths : {}
81
- });
82
- return result;
83
- };
84
- const writeDtsFiles = async (config, result) => {
85
- const { dtsExtension } = config;
86
- await Promise.all(result.map(({ path, content }) => {
87
- const filepath = (
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 = (
88
130
  // We confirm that users will not mix ts and c(m)ts files in their projects.
89
131
  // If a mix is required, please configure separate buildConfig to handle different inputs.
90
132
  // So we don't replace .d.(c|m)ts that generated by tsc directly, this can confirm that
91
133
  // users can use c(m)ts directly rather than enable autoExtension, in this condition,
92
134
  // users need to set esbuild out-extensions like { '.js': '.mjs' }
93
- path.replace(/\.d\.ts/, dtsExtension)
135
+ filePath.replace(/\.d\.ts/, dtsExtension)
94
136
  );
95
- import_utils.fs.ensureFileSync(filepath);
96
137
  return import_utils.fs.writeFile(
97
138
  // only replace .d.ts, if tsc generate .d.m(c)ts, keep.
98
- filepath,
139
+ finalPath,
99
140
  content
100
141
  );
101
142
  }));
102
143
  };
103
- const addBannerAndFooter = (result, banner, footer) => {
104
- return result.map(({ path, content }) => {
105
- const ms = new import_magic_string.default(content);
106
- banner && ms.prepend(`${banner}
107
- `);
108
- footer && ms.append(`
109
- ${footer}
110
- `);
111
- return {
112
- path,
113
- content: ms.toString()
114
- };
115
- });
116
- };
117
144
  const printOrThrowDtsErrors = async (error, options) => {
118
145
  const { InternalDTSError } = await Promise.resolve().then(() => __toESM(require("../error")));
119
146
  const local = await Promise.resolve().then(() => __toESM(require("../locale")));
@@ -134,11 +161,9 @@ const printOrThrowDtsErrors = async (error, options) => {
134
161
  const tsTargetAtOrAboveES2022 = (target) => target === "es2022" || target === "esnext";
135
162
  // Annotate the CommonJS export names for ESM import in node:
136
163
  0 && (module.exports = {
137
- addBannerAndFooter,
138
164
  getProjectTsconfig,
139
165
  getTscBinPath,
140
166
  printOrThrowDtsErrors,
141
- resolveAlias,
142
- tsTargetAtOrAboveES2022,
143
- writeDtsFiles
167
+ processDtsFilesAfterTsc,
168
+ tsTargetAtOrAboveES2022
144
169
  });
@@ -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;
@@ -8,5 +8,4 @@ export * from './log';
8
8
  export * from './map';
9
9
  export * from './print';
10
10
  export * from './style';
11
- export * from './tspath';
12
- export * from './outExtension';
11
+ export * from './outExtension';
@@ -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
  });
@@ -1,11 +1,8 @@
1
1
  import { Input } from '../types';
2
- export declare const getDefaultIndexEntry: ({
3
- isTsProject,
4
- appDirectory
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
- [name: string]: string;
11
- }>;
7
+ [name: string]: string;
8
+ }>;
@@ -1 +1 @@
1
- export declare const withLogTitle: (titleText: string, message: string) => string;
1
+ export declare const withLogTitle: (titleText: string, message: string) => string;
@@ -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
- needSourceMap: boolean;
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
- toString: () => string;
9
- toMap: () => SourceMap;
10
- toComment: () => string;
8
+ toString: () => string;
9
+ toMap: () => SourceMap;
10
+ toComment: () => string;
11
11
  };
12
12
  export declare function mergeMaps(mapList: SourceMap[]): MergeMapResult;
13
- export {};
13
+ export {};
@@ -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
- format: Format;
4
- root: string;
5
- autoExtension: boolean;
3
+ format: Format;
4
+ root: string;
5
+ autoExtension: boolean;
6
6
  }) => {
7
- jsExtension: string;
8
- dtsExtension: string;
9
- };
7
+ jsExtension: string;
8
+ dtsExtension: string;
9
+ };