@modern-js/module-tools 2.5.2-beta.4 → 2.7.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/CHANGELOG.md +59 -0
- package/compiled/rollup-plugin-dts/dist/rollup-plugin-dts.d.ts +106 -3
- package/compiled/rollup-plugin-dts/package.json +1 -1
- package/dist/build.js +6 -0
- package/dist/build.js.map +1 -0
- package/dist/builder/build.js +11 -4
- package/dist/builder/build.js.map +1 -0
- package/dist/builder/clear.js +6 -0
- package/dist/builder/clear.js.map +1 -0
- package/dist/builder/copy.d.ts +6 -1
- package/dist/builder/copy.js +71 -13
- package/dist/builder/copy.js.map +1 -0
- package/dist/builder/dts/index.js +2 -0
- package/dist/builder/dts/index.js.map +1 -0
- package/dist/builder/dts/rollup.js +19 -1
- package/dist/builder/dts/rollup.js.map +1 -0
- package/dist/builder/dts/tsc.js +8 -0
- package/dist/builder/dts/tsc.js.map +1 -0
- package/dist/builder/index.js +6 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/platform.js +6 -0
- package/dist/builder/platform.js.map +1 -0
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -0
- package/dist/command.js +6 -0
- package/dist/command.js.map +1 -0
- package/dist/config/defineConfig.js +2 -0
- package/dist/config/defineConfig.js.map +1 -0
- package/dist/config/{legacy-schema.js → legacySchema.js} +12 -3
- package/dist/config/legacySchema.js.map +1 -0
- package/dist/config/normalize.js +8 -2
- package/dist/config/normalize.js.map +1 -0
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +6 -2
- package/dist/config/schema.js.map +1 -0
- package/dist/config/{transform-legacy-config.js → transformLegacyConfig.js} +11 -5
- package/dist/config/transformLegacyConfig.js.map +1 -0
- package/dist/constants/build.js +2 -0
- package/dist/constants/build.js.map +1 -0
- package/dist/constants/{build-presets.js → buildPresets.js} +5 -3
- package/dist/constants/buildPresets.js.map +1 -0
- package/dist/constants/colors.js +2 -0
- package/dist/constants/colors.js.map +1 -0
- package/dist/constants/dts.js +4 -0
- package/dist/constants/dts.js.map +1 -0
- package/dist/constants/file.js +2 -0
- package/dist/constants/file.js.map +1 -0
- package/dist/constants/{legacy-build-presets.js → legacyBuildPresets.js} +9 -3
- package/dist/constants/legacyBuildPresets.js.map +1 -0
- package/dist/constants/log.d.ts +1 -0
- package/dist/constants/log.js +5 -0
- package/dist/constants/log.js.map +1 -0
- package/dist/dev.js +6 -0
- package/dist/dev.js.map +1 -0
- package/dist/error.js +2 -0
- package/dist/error.js.map +1 -0
- package/dist/hooks/build.js +2 -0
- package/dist/hooks/build.js.map +1 -0
- package/dist/hooks/dev.js +3 -0
- package/dist/hooks/dev.js.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/misc.js +2 -0
- package/dist/hooks/misc.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -0
- package/dist/locale/en.js +2 -0
- package/dist/locale/en.js.map +1 -0
- package/dist/locale/index.js +2 -0
- package/dist/locale/index.js.map +1 -0
- package/dist/locale/zh.js +2 -0
- package/dist/locale/zh.js.map +1 -0
- package/dist/plugins.js +6 -0
- package/dist/plugins.js.map +1 -0
- package/dist/types/color.js +2 -0
- package/dist/types/color.js.map +1 -0
- package/dist/types/command.js +2 -0
- package/dist/types/command.js.map +1 -0
- package/dist/types/config/index.d.ts +1 -1
- package/dist/types/config/index.js +2 -0
- package/dist/types/config/index.js.map +1 -0
- package/dist/types/config/style.js +2 -0
- package/dist/types/config/style.js.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/copy.js +2 -0
- package/dist/types/copy.js.map +1 -0
- package/dist/types/dts.js +2 -0
- package/dist/types/dts.js.map +1 -0
- package/dist/types/hooks.js +2 -0
- package/dist/types/hooks.js.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/legacyConfig/index.js +2 -0
- package/dist/types/legacyConfig/index.js.map +1 -0
- package/dist/types/legacyConfig/output.js +2 -0
- package/dist/types/legacyConfig/output.js.map +1 -0
- package/dist/types/legacyConfig/source.js +2 -0
- package/dist/types/legacyConfig/source.js.map +1 -0
- package/dist/types/legacyConfig/tools.js +2 -0
- package/dist/types/legacyConfig/tools.js.map +1 -0
- package/dist/types/utils.js +2 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/utils/builder.js +6 -0
- package/dist/utils/builder.js.map +1 -0
- package/dist/utils/config.js +6 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/context.js +6 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/dts.js +8 -1
- package/dist/utils/dts.js.map +1 -0
- package/dist/utils/input.js +6 -0
- package/dist/utils/input.js.map +1 -0
- package/dist/utils/language.js +6 -0
- package/dist/utils/language.js.map +1 -0
- package/dist/utils/{libuild-plugins.js → libuildPlugins.js} +9 -3
- package/dist/utils/libuildPlugins.js.map +1 -0
- package/dist/utils/log.d.ts +1 -1
- package/dist/utils/log.js +8 -2
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/onExit.js +6 -0
- package/dist/utils/onExit.js.map +1 -0
- package/dist/utils/path.js +6 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/print.js +7 -0
- package/dist/utils/print.js.map +1 -0
- package/dist/utils/style.js +8 -0
- package/dist/utils/style.js.map +1 -0
- package/dist/utils/{tspaths-transform.js → tspathsTransform.js} +12 -3
- package/dist/utils/tspathsTransform.js.map +1 -0
- package/package.json +20 -18
- package/scripts/debug-mode.js +49 -0
- /package/dist/config/{legacy-schema.d.ts → legacySchema.d.ts} +0 -0
- /package/dist/config/{transform-legacy-config.d.ts → transformLegacyConfig.d.ts} +0 -0
- /package/dist/constants/{build-presets.d.ts → buildPresets.d.ts} +0 -0
- /package/dist/constants/{legacy-build-presets.d.ts → legacyBuildPresets.d.ts} +0 -0
- /package/dist/utils/{libuild-plugins.d.ts → libuildPlugins.d.ts} +0 -0
- /package/dist/utils/{tspaths-transform.d.ts → tspathsTransform.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# @modern-js/module-tools
|
|
2
2
|
|
|
3
|
+
## 2.7.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eccfe877b5: fix: add watch mode to copy
|
|
8
|
+
fix: 为 copy 功能补充 watch 逻辑
|
|
9
|
+
- 7fff9020e1: chore: make file naming consistent
|
|
10
|
+
|
|
11
|
+
chore: 统一文件命名为小驼峰格式
|
|
12
|
+
|
|
13
|
+
- 1eea234fdd: chore: make test files naming consistent
|
|
14
|
+
|
|
15
|
+
chore: 统一测试文件命名为小驼峰格式
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [206c806efa]
|
|
18
|
+
- Updated dependencies [0f15fc597c]
|
|
19
|
+
- Updated dependencies [dcad887024]
|
|
20
|
+
- Updated dependencies [a4672f7c16]
|
|
21
|
+
- Updated dependencies [7fff9020e1]
|
|
22
|
+
- Updated dependencies [1eea234fdd]
|
|
23
|
+
- Updated dependencies [84bfb439b8]
|
|
24
|
+
- @modern-js/core@2.7.0
|
|
25
|
+
- @modern-js/utils@2.7.0
|
|
26
|
+
- @modern-js/plugin-changeset@2.7.0
|
|
27
|
+
- @modern-js/plugin-i18n@2.7.0
|
|
28
|
+
- @modern-js/plugin-lint@2.7.0
|
|
29
|
+
- @modern-js/new-action@2.7.0
|
|
30
|
+
- @modern-js/upgrade@2.7.0
|
|
31
|
+
- @modern-js/plugin@2.7.0
|
|
32
|
+
|
|
33
|
+
## 2.6.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- c1918f5: feat(module-tools): add new Buildpreset and `extendPreset` function
|
|
38
|
+
feat(module-tools): 新增新的 buildPreset 以及 extendPreset 函数
|
|
39
|
+
- 9d1905a: feat: support to handle files add and unlink in watch mode
|
|
40
|
+
feat: 支持在 watch 模式下处理文件的新增和删除
|
|
41
|
+
- 44e7b10: feat: add noDevTools hook. fix dev log content and add add chinese and english content
|
|
42
|
+
feat: 增加 noDevTools hook. 修复 dev 的日志内容, 增加中英内容
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 5f66bc5: fix(module-tools): fix copy context error path
|
|
47
|
+
fix(module-tools): 修复 copy context 错误路径的问题
|
|
48
|
+
- f0e41e7: fix: set composite false in bundle dts
|
|
49
|
+
fix: 打包 d.ts 时设置 composite 为 false
|
|
50
|
+
- Updated dependencies [e1f799e]
|
|
51
|
+
- Updated dependencies [7915ab3]
|
|
52
|
+
- Updated dependencies [0fe658a]
|
|
53
|
+
- @modern-js/utils@2.6.0
|
|
54
|
+
- @modern-js/core@2.6.0
|
|
55
|
+
- @modern-js/plugin-changeset@2.6.0
|
|
56
|
+
- @modern-js/plugin-i18n@2.6.0
|
|
57
|
+
- @modern-js/plugin-lint@2.6.0
|
|
58
|
+
- @modern-js/new-action@2.6.0
|
|
59
|
+
- @modern-js/upgrade@2.6.0
|
|
60
|
+
- @modern-js/plugin@2.6.0
|
|
61
|
+
|
|
3
62
|
## 2.5.0
|
|
4
63
|
|
|
5
64
|
### Minor Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as rollup from '../rollup';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
|
|
4
4
|
interface Options {
|
|
@@ -20,6 +20,109 @@ interface Options {
|
|
|
20
20
|
*/
|
|
21
21
|
tsconfig?: string;
|
|
22
22
|
}
|
|
23
|
-
declare const plugin: PluginImpl<Options>;
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
declare function rollupPluginDts(options?: Options): {
|
|
25
|
+
name: string;
|
|
26
|
+
outputOptions: (this: rollup.PluginContext, options: rollup.OutputOptions) => {
|
|
27
|
+
chunkFileNames: string | ((chunkInfo: rollup.PreRenderedChunk) => string);
|
|
28
|
+
entryFileNames: string | ((chunkInfo: rollup.PreRenderedChunk) => string);
|
|
29
|
+
format: "es";
|
|
30
|
+
exports: "named";
|
|
31
|
+
compact: false;
|
|
32
|
+
freeze: true;
|
|
33
|
+
interop: "esModule";
|
|
34
|
+
generatedCode: {
|
|
35
|
+
symbols: boolean;
|
|
36
|
+
} & (rollup.GeneratedCodePreset | rollup.GeneratedCodeOptions | undefined);
|
|
37
|
+
strict: false;
|
|
38
|
+
amd?: rollup.AmdOptions | undefined;
|
|
39
|
+
assetFileNames?: string | ((chunkInfo: rollup.PreRenderedAsset) => string) | undefined;
|
|
40
|
+
banner?: string | rollup.AddonFunction | undefined;
|
|
41
|
+
dir?: string | undefined;
|
|
42
|
+
dynamicImportFunction?: string | undefined;
|
|
43
|
+
dynamicImportInCjs?: boolean | undefined;
|
|
44
|
+
esModule?: boolean | "if-default-prop" | undefined;
|
|
45
|
+
experimentalDeepDynamicChunkOptimization?: boolean | undefined;
|
|
46
|
+
experimentalMinChunkSize?: number | undefined;
|
|
47
|
+
extend?: boolean | undefined;
|
|
48
|
+
externalImportAssertions?: boolean | undefined;
|
|
49
|
+
externalLiveBindings?: boolean | undefined;
|
|
50
|
+
file?: string | undefined;
|
|
51
|
+
footer?: string | rollup.AddonFunction | undefined;
|
|
52
|
+
globals?: rollup.GlobalsOption | undefined;
|
|
53
|
+
hoistTransitiveImports?: boolean | undefined;
|
|
54
|
+
indent?: string | boolean | undefined;
|
|
55
|
+
inlineDynamicImports?: boolean | undefined;
|
|
56
|
+
intro?: string | rollup.AddonFunction | undefined;
|
|
57
|
+
manualChunks?: rollup.ManualChunksOption | undefined;
|
|
58
|
+
minifyInternalExports?: boolean | undefined;
|
|
59
|
+
name?: string | undefined;
|
|
60
|
+
namespaceToStringTag?: boolean | undefined;
|
|
61
|
+
noConflict?: boolean | undefined;
|
|
62
|
+
outro?: string | rollup.AddonFunction | undefined;
|
|
63
|
+
paths?: rollup.OptionsPaths | undefined;
|
|
64
|
+
plugins?: rollup.OutputPluginOption;
|
|
65
|
+
preferConst?: boolean | undefined;
|
|
66
|
+
preserveModules?: boolean | undefined;
|
|
67
|
+
preserveModulesRoot?: string | undefined;
|
|
68
|
+
sanitizeFileName?: boolean | ((fileName: string) => string) | undefined;
|
|
69
|
+
sourcemap?: boolean | "inline" | "hidden" | undefined;
|
|
70
|
+
sourcemapBaseUrl?: string | undefined;
|
|
71
|
+
sourcemapExcludeSources?: boolean | undefined;
|
|
72
|
+
sourcemapFile?: string | undefined;
|
|
73
|
+
sourcemapPathTransform?: rollup.SourcemapPathTransformOption | undefined;
|
|
74
|
+
systemNullSetters?: boolean | undefined;
|
|
75
|
+
validate?: boolean | undefined;
|
|
76
|
+
};
|
|
77
|
+
renderChunk: (this: rollup.PluginContext, code: string, chunk: rollup.RenderedChunk, options: rollup.NormalizedOutputOptions) => {
|
|
78
|
+
code: string;
|
|
79
|
+
map: {
|
|
80
|
+
mappings: "";
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
options(this: rollup.MinimalPluginContext, options: rollup.InputOptions): {
|
|
84
|
+
onwarn(warning: rollup.RollupLog, warn: rollup.WarningHandler): void;
|
|
85
|
+
treeshake: {
|
|
86
|
+
moduleSideEffects: "no-external";
|
|
87
|
+
propertyReadSideEffects: true;
|
|
88
|
+
unknownGlobalSideEffects: false;
|
|
89
|
+
};
|
|
90
|
+
acorn?: Record<string, unknown> | undefined;
|
|
91
|
+
acornInjectPlugins?: (() => unknown)[] | (() => unknown) | undefined;
|
|
92
|
+
cache?: false | rollup.RollupCache | undefined;
|
|
93
|
+
context?: string | undefined;
|
|
94
|
+
experimentalCacheExpiry?: number | undefined;
|
|
95
|
+
external?: rollup.ExternalOption | undefined;
|
|
96
|
+
inlineDynamicImports?: boolean | undefined;
|
|
97
|
+
input?: rollup.InputOption | undefined;
|
|
98
|
+
makeAbsoluteExternalsRelative?: boolean | "ifRelativeSource" | undefined;
|
|
99
|
+
manualChunks?: rollup.ManualChunksOption | undefined;
|
|
100
|
+
maxParallelFileOps?: number | undefined;
|
|
101
|
+
maxParallelFileReads?: number | undefined;
|
|
102
|
+
moduleContext?: ((id: string) => string | rollup.NullValue) | {
|
|
103
|
+
[id: string]: string;
|
|
104
|
+
} | undefined;
|
|
105
|
+
perf?: boolean | undefined;
|
|
106
|
+
plugins?: rollup.InputPluginOption;
|
|
107
|
+
preserveEntrySignatures?: rollup.PreserveEntrySignaturesOption | undefined;
|
|
108
|
+
preserveModules?: boolean | undefined;
|
|
109
|
+
preserveSymlinks?: boolean | undefined;
|
|
110
|
+
shimMissingExports?: boolean | undefined;
|
|
111
|
+
strictDeprecations?: boolean | undefined;
|
|
112
|
+
watch?: false | rollup.WatcherOptions | undefined;
|
|
113
|
+
};
|
|
114
|
+
transform(this: rollup.TransformPluginContext, code: string, id: string): {
|
|
115
|
+
code: string;
|
|
116
|
+
ast: any;
|
|
117
|
+
map: any;
|
|
118
|
+
} | null;
|
|
119
|
+
resolveId(this: rollup.PluginContext, source: string, importer: string | undefined): {
|
|
120
|
+
id: string;
|
|
121
|
+
external: true;
|
|
122
|
+
} | {
|
|
123
|
+
id: string;
|
|
124
|
+
external?: undefined;
|
|
125
|
+
} | undefined;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export { Options, rollupPluginDts as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"rollup-plugin-dts","author":"Arpad Borsos <arpad.borsos@googlemail.com>","version":"5.
|
|
1
|
+
{"name":"rollup-plugin-dts","author":"Arpad Borsos <arpad.borsos@googlemail.com>","version":"5.2.0","funding":{"url":"https://github.com/sponsors/Swatinem"},"license":"LGPL-3.0","types":"./dist/rollup-plugin-dts.d.ts"}
|
package/dist/build.js
CHANGED
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -69,3 +73,5 @@ const build = (api, options, context) => __async(void 0, null, function* () {
|
|
|
69
73
|
0 && (module.exports = {
|
|
70
74
|
build
|
|
71
75
|
});
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA+B;AAG/B,MAAM,YAAQ,6BAAe,cAAc;AAEpC,MAAM,QAAQ,CACnB,KACA,SACA,YACG;AACH,MAAI,QAAQ,UAAU;AACpB,UAAM,EAAE,cAAc,IAAI,MAAM,6CAAO,oBAAoB;AAC3D,UAAM,cAAc,SAAS,KAAK,OAAO;AACzC;AAAA,EACF;AAEA,QAAM,SAAS,IAAI,eAAe;AAElC,QAAM,EAAE,qBAAqB,IAAI,MAAM,6CAAO,oBAAoB;AAClE,QAAM,sBAAsB,MAAM,qBAAqB,KAAK,SAAS,OAAO;AAE5E,QAAM,uBAAuB,mBAAmB;AAEhD,QAAM,OAAO,YAAY;AAAA,IACvB,QAAQ;AAAA,IACR,YAAY;AAAA,EACd,CAAC;AACD,QAAM,UAAU,MAAM,6CAAO,WAAW;AACxC,QAAM,QAAQ,IAAI,EAAE,YAAY,SAAS,qBAAqB,QAAQ,GAAG,GAAG;AAC9E;;;;;","names":[],"sources":["../src/build.ts"],"sourcesContent":["import type { PluginAPI } from '@modern-js/core';\nimport { createDebugger } from '@modern-js/utils';\nimport type { ModuleTools, ModuleContext, BuildCommandOptions } from './types';\n\nconst debug = createDebugger('module-tools');\n\nexport const build = async (\n api: PluginAPI<ModuleTools>,\n options: BuildCommandOptions,\n context: ModuleContext,\n) => {\n if (options.platform) {\n const { buildPlatform } = await import('./builder/platform');\n await buildPlatform(options, api, context);\n return;\n }\n\n const runner = api.useHookRunners();\n\n const { normalizeBuildConfig } = await import('./config/normalize');\n const resolvedBuildConfig = await normalizeBuildConfig(api, context, options);\n\n debug('resolvedBuildConfig', resolvedBuildConfig);\n\n await runner.beforeBuild({\n config: resolvedBuildConfig,\n cliOptions: options,\n });\n const builder = await import('./builder');\n await builder.run({ cmdOptions: options, resolvedBuildConfig, context }, api);\n};\n"]}
|
package/dist/builder/build.js
CHANGED
|
@@ -34,6 +34,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
34
34
|
return to;
|
|
35
35
|
};
|
|
36
36
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
41
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
42
|
mod
|
|
39
43
|
));
|
|
@@ -69,15 +73,15 @@ __export(build_exports, {
|
|
|
69
73
|
module.exports = __toCommonJS(build_exports);
|
|
70
74
|
var import_path = require("path");
|
|
71
75
|
const runBuildTask = (options, api) => __async(void 0, null, function* () {
|
|
72
|
-
const { buildConfig, context } = options;
|
|
76
|
+
const { buildConfig, context, buildCmdOptions } = options;
|
|
73
77
|
const { appDirectory, isTsProject } = context;
|
|
78
|
+
const { copyTask } = yield Promise.resolve().then(() => __toESM(require("./copy")));
|
|
79
|
+
yield copyTask(buildConfig, { appDirectory, watch: buildCmdOptions.watch });
|
|
74
80
|
if (isTsProject) {
|
|
75
81
|
yield buildInTsProject(options, api);
|
|
76
82
|
} else {
|
|
77
83
|
yield buildInJsProject(options, api);
|
|
78
84
|
}
|
|
79
|
-
const { copyTask } = yield Promise.resolve().then(() => __toESM(require("./copy")));
|
|
80
|
-
yield copyTask(buildConfig, { appDirectory });
|
|
81
85
|
});
|
|
82
86
|
const buildInTsProject = (options, api) => __async(void 0, null, function* () {
|
|
83
87
|
var _a;
|
|
@@ -190,7 +194,7 @@ const buildLib = (config, api, options) => __async(void 0, null, function* () {
|
|
|
190
194
|
const options2 = typeof asset.svgr === "boolean" ? {} : asset.svgr;
|
|
191
195
|
plugins.push(svgrPlugin(options2));
|
|
192
196
|
}
|
|
193
|
-
const { watchPlugin, externalPlugin } = yield Promise.resolve().then(() => __toESM(require("../utils/
|
|
197
|
+
const { watchPlugin, externalPlugin } = yield Promise.resolve().then(() => __toESM(require("../utils/libuildPlugins")));
|
|
194
198
|
plugins.push(watchPlugin(api, config));
|
|
195
199
|
plugins.push(externalPlugin(config, { appDirectory }));
|
|
196
200
|
const buildConfig = {
|
|
@@ -228,6 +232,7 @@ const buildLib = (config, api, options) => __async(void 0, null, function* () {
|
|
|
228
232
|
autoExternal,
|
|
229
233
|
bundle: buildType === "bundle",
|
|
230
234
|
sideEffects,
|
|
235
|
+
// outbase for [dir]/[name]
|
|
231
236
|
outbase: sourceDir,
|
|
232
237
|
esbuildOptions: (options2) => __spreadProps(__spreadValues({}, options2), {
|
|
233
238
|
supported: {
|
|
@@ -270,3 +275,5 @@ const buildLib = (config, api, options) => __async(void 0, null, function* () {
|
|
|
270
275
|
generatorDts,
|
|
271
276
|
runBuildTask
|
|
272
277
|
});
|
|
278
|
+
|
|
279
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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;;;;;;;","names":["options"],"sources":["../../src/builder/build.ts"],"sourcesContent":["import { join } from 'path';\nimport type { CLIConfig } from '@modern-js/libuild';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n PluginAPI,\n DTSOptions,\n ModuleContext,\n} from '../types';\n\nexport const runBuildTask = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, context, buildCmdOptions } = options;\n const { appDirectory, isTsProject } = context;\n\n const { copyTask } = await import('./copy');\n await copyTask(buildConfig, { appDirectory, watch: buildCmdOptions.watch });\n\n if (isTsProject) {\n await buildInTsProject(options, api);\n } else {\n await buildInJsProject(options, api);\n }\n};\n\nexport const buildInTsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const skipBuildLib = buildConfig.dts ? buildConfig.dts.only : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts === false) {\n // --no-dts and buildConfig is `{ dts: { only: true } }`, then skip.\n !skipBuildLib && (await buildLib(buildConfig, api, { watch }));\n } else {\n const tasks = dts.only ? [generatorDts] : [buildLib, generatorDts];\n const { default: pMap } = await import('../../compiled/p-map');\n await pMap(tasks, async task => {\n await task(buildConfig, api as any, { watch, dts });\n });\n }\n};\n\nexport const buildInJsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts !== false && dts.only) {\n return;\n }\n\n await buildLib(buildConfig, api, { watch });\n};\n\nexport const generatorDts = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n dts: DTSOptions;\n },\n) => {\n const { runRollup, runTsc } = await import('./dts');\n const { watch, dts } = options;\n const { buildType, input, sourceDir, alias } = config;\n const { appDirectory } = api.useAppContext();\n const { tsconfigPath, distPath } = dts;\n if (buildType === 'bundle') {\n const { getFinalExternals } = await import('../utils/builder');\n const finalExternals = await getFinalExternals(config, { appDirectory });\n\n await runRollup(api, {\n distDir: distPath,\n watch,\n externals: finalExternals,\n input,\n tsconfigPath,\n });\n } else {\n await runTsc(api, {\n appDirectory,\n alias,\n distAbsPath: distPath,\n watch,\n tsconfigPath,\n sourceDir,\n });\n }\n};\n\nexport const buildLib = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n },\n) => {\n const { watch } = options;\n const {\n target,\n buildType,\n sourceMap,\n format,\n outDir: distPath,\n asset,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n umdGlobals,\n umdModuleName,\n define,\n alias,\n style,\n externals,\n autoExternal,\n dts,\n metafile,\n sideEffects,\n } = config;\n const { appDirectory } = api.useAppContext();\n const { slash } = await import('@modern-js/utils');\n const root = slash(appDirectory);\n const outdir = slash(distPath);\n const assetOutDir = asset.path ? slash(asset.path) : asset.path;\n const { less, sass, postcss, inject, modules, autoModules } = style;\n\n // support es5,umd and emitDecoratorMetadata by swc\n const { es5Plugin, umdPlugin, transformPlugin } = await import(\n '@modern-js/libuild-plugin-swc'\n );\n const plugins = format === 'umd' ? [umdPlugin(umdModuleName)] : [];\n if (target === 'es5') {\n plugins.push(es5Plugin());\n }\n const { getProjectTsconfig } = await import('./dts/tsc');\n const tsconfigPath = dts\n ? dts.tsconfigPath\n : join(appDirectory, './tsconfig.json');\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n if (userTsconfig?.compilerOptions?.emitDecoratorMetadata) {\n plugins.push(\n transformPlugin({\n jsc: {\n transform: {\n legacyDecorator: true,\n decoratorMetadata: true,\n },\n },\n }),\n );\n }\n\n // support svgr\n if (asset.svgr) {\n const { svgrPlugin } = await import('@modern-js/libuild-plugin-svgr');\n const options = typeof asset.svgr === 'boolean' ? {} : asset.svgr;\n plugins.push(svgrPlugin(options));\n }\n\n // adapt module tools\n const { watchPlugin, externalPlugin } = await import(\n '../utils/libuildPlugins'\n );\n plugins.push(watchPlugin(api, config));\n plugins.push(externalPlugin(config, { appDirectory }));\n\n const buildConfig: CLIConfig = {\n root,\n watch,\n target,\n sourceMap,\n format,\n outdir,\n define,\n style: {\n less,\n sass,\n postcss,\n inject,\n modules,\n autoModules,\n },\n resolve: {\n alias,\n },\n asset: {\n ...asset,\n outdir: assetOutDir,\n },\n plugins,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n metafile: metafile && buildType === 'bundle',\n globals: umdGlobals,\n external: externals,\n autoExternal,\n bundle: buildType === 'bundle',\n sideEffects,\n // outbase for [dir]/[name]\n outbase: sourceDir,\n esbuildOptions: (options: any) => ({\n ...options,\n supported: {\n 'dynamic-import': !(\n ['cjs', 'umd'].includes(format) && buildType === 'bundleless'\n ),\n },\n }),\n };\n\n try {\n const { Libuilder } = await import('@modern-js/libuild');\n const { addOutputChunk } = await import('../utils/print');\n const runner = api.useHookRunners();\n const modifiedBuildConfig = await runner.modifyLibuild(buildConfig, {\n onLast: c => c,\n });\n\n const builder = await Libuilder.create(modifiedBuildConfig);\n await builder.build();\n addOutputChunk(builder.outputChunk, root, buildType === 'bundle');\n\n if (watch) {\n const { watchSectionTitle } = await import('../utils/log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }: ${format}_${target}]`;\n\n console.info(\n await watchSectionTitle(titleText, SectionTitleStatus.Success),\n );\n }\n } catch (e: any) {\n const { InternalBuildError } = await import('../error');\n throw new InternalBuildError(e, {\n target,\n format,\n buildType,\n });\n }\n};\n"]}
|
package/dist/builder/clear.js
CHANGED
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -63,3 +67,5 @@ const clearBuildConfigPaths = (configs) => __async(void 0, null, function* () {
|
|
|
63
67
|
clearBuildConfigPaths,
|
|
64
68
|
clearDtsTemp
|
|
65
69
|
});
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=clear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,eAAe,MAAY;AACtC,QAAM,EAAE,GAAG,IAAI,MAAM,6CAAO,kBAAkB;AAC9C,QAAM,EAAE,iBAAiB,IAAI,MAAM,6CAAO,kBAAkB;AAC5D,QAAM,GAAG,OAAO,gBAAgB;AAClC;AAEO,MAAM,wBAAwB,CAAO,YAA+B;AACzE,QAAM,EAAE,GAAG,IAAI,MAAM,6CAAO,kBAAkB;AAE9C,aAAW,UAAU,SAAS;AAC5B,UAAM,GAAG,OAAO,OAAO,MAAM;AAAA,EAC/B;AACF;;;;;;","names":[],"sources":["../../src/builder/clear.ts"],"sourcesContent":["import type { BaseBuildConfig } from '../types';\n\nexport const clearDtsTemp = async () => {\n const { fs } = await import('@modern-js/utils');\n const { dtsTempDirectory } = await import('../constants/dts');\n await fs.remove(dtsTempDirectory);\n};\n\nexport const clearBuildConfigPaths = async (configs: BaseBuildConfig[]) => {\n const { fs } = await import('@modern-js/utils');\n\n for (const config of configs) {\n await fs.remove(config.outDir);\n }\n};\n"]}
|
package/dist/builder/copy.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type { CopyPattern } from '../types/copy';
|
|
1
|
+
import type { CopyOptions, CopyPattern } from '../types/copy';
|
|
2
2
|
import type { BaseBuildConfig } from '../types/config';
|
|
3
3
|
export declare const runPatterns: (pattern: CopyPattern, options: {
|
|
4
4
|
appDirectory: string;
|
|
5
5
|
enableCopySync?: boolean;
|
|
6
6
|
outDir: string;
|
|
7
7
|
defaultContext: string;
|
|
8
|
+
watch?: boolean;
|
|
8
9
|
}) => Promise<void>;
|
|
10
|
+
export declare const watchCopyFiles: (options: {
|
|
11
|
+
appDirectory: string;
|
|
12
|
+
}, copyConfig: CopyOptions) => Promise<void>;
|
|
9
13
|
export declare const copyTask: (buildConfig: BaseBuildConfig, options: {
|
|
10
14
|
appDirectory: string;
|
|
15
|
+
watch?: boolean;
|
|
11
16
|
}) => Promise<void>;
|
package/dist/builder/copy.js
CHANGED
|
@@ -34,6 +34,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
34
34
|
return to;
|
|
35
35
|
};
|
|
36
36
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
41
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
42
|
mod
|
|
39
43
|
));
|
|
@@ -61,28 +65,31 @@ var __async = (__this, __arguments, generator) => {
|
|
|
61
65
|
var copy_exports = {};
|
|
62
66
|
__export(copy_exports, {
|
|
63
67
|
copyTask: () => copyTask,
|
|
64
|
-
runPatterns: () => runPatterns
|
|
68
|
+
runPatterns: () => runPatterns,
|
|
69
|
+
watchCopyFiles: () => watchCopyFiles
|
|
65
70
|
});
|
|
66
71
|
module.exports = __toCommonJS(copy_exports);
|
|
67
72
|
var import_path = __toESM(require("path"));
|
|
73
|
+
const watchMap = /* @__PURE__ */ new Map();
|
|
68
74
|
const runPatterns = (pattern, options) => __async(void 0, null, function* () {
|
|
69
75
|
var _a;
|
|
70
76
|
const { fs, fastGlob, globby } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
71
77
|
const { default: normalizePath } = yield Promise.resolve().then(() => __toESM(require("../../compiled/normalize-path")));
|
|
72
78
|
const { appDirectory, enableCopySync = false } = options;
|
|
73
79
|
const { from, globOptions = {} } = pattern;
|
|
80
|
+
const targetPattern = __spreadValues({}, pattern);
|
|
74
81
|
const normalizedFrom = import_path.default.normalize(from);
|
|
75
82
|
const defaultAbsContext = options.defaultContext;
|
|
76
83
|
if (typeof pattern.context === "string") {
|
|
77
|
-
|
|
84
|
+
targetPattern.context = import_path.default.isAbsolute(pattern.context) ? pattern.context : import_path.default.join(appDirectory, pattern.context);
|
|
78
85
|
} else {
|
|
79
|
-
|
|
86
|
+
targetPattern.context = defaultAbsContext;
|
|
80
87
|
}
|
|
81
88
|
let absoluteFrom;
|
|
82
89
|
if (import_path.default.isAbsolute(normalizedFrom)) {
|
|
83
90
|
absoluteFrom = normalizedFrom;
|
|
84
91
|
} else {
|
|
85
|
-
absoluteFrom = import_path.default.resolve(
|
|
92
|
+
absoluteFrom = import_path.default.resolve(targetPattern.context, normalizedFrom);
|
|
86
93
|
}
|
|
87
94
|
let stats;
|
|
88
95
|
try {
|
|
@@ -104,7 +111,7 @@ const runPatterns = (pattern, options) => __async(void 0, null, function* () {
|
|
|
104
111
|
let glob;
|
|
105
112
|
switch (fromType) {
|
|
106
113
|
case "dir":
|
|
107
|
-
|
|
114
|
+
targetPattern.context = absoluteFrom;
|
|
108
115
|
glob = import_path.default.posix.join(
|
|
109
116
|
fastGlob.escapePath(normalizePath(import_path.default.resolve(absoluteFrom))),
|
|
110
117
|
"**/*"
|
|
@@ -115,7 +122,7 @@ const runPatterns = (pattern, options) => __async(void 0, null, function* () {
|
|
|
115
122
|
}
|
|
116
123
|
break;
|
|
117
124
|
case "file":
|
|
118
|
-
|
|
125
|
+
targetPattern.context = import_path.default.dirname(absoluteFrom);
|
|
119
126
|
glob = fastGlob.escapePath(normalizePath(import_path.default.resolve(absoluteFrom)));
|
|
120
127
|
if (typeof globOptions.dot === "undefined") {
|
|
121
128
|
globOptions.dot = true;
|
|
@@ -125,14 +132,16 @@ const runPatterns = (pattern, options) => __async(void 0, null, function* () {
|
|
|
125
132
|
default: {
|
|
126
133
|
glob = import_path.default.isAbsolute(from) ? from : import_path.default.posix.join(
|
|
127
134
|
fastGlob.escapePath(
|
|
128
|
-
normalizePath(
|
|
135
|
+
normalizePath(
|
|
136
|
+
import_path.default.resolve((_a = targetPattern.context) != null ? _a : appDirectory)
|
|
137
|
+
)
|
|
129
138
|
),
|
|
130
139
|
from
|
|
131
140
|
);
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
|
-
const globEntries = yield globby(glob, __spreadProps(__spreadValues(__spreadValues({}, { followSymbolicLinks: true }),
|
|
135
|
-
cwd:
|
|
143
|
+
const globEntries = yield globby(glob, __spreadProps(__spreadValues(__spreadValues({}, { followSymbolicLinks: true }), targetPattern.globOptions || {}), {
|
|
144
|
+
cwd: targetPattern.context,
|
|
136
145
|
objectMode: true
|
|
137
146
|
}));
|
|
138
147
|
const { default: pMap } = yield Promise.resolve().then(() => __toESM(require("../../compiled/p-map")));
|
|
@@ -142,17 +151,20 @@ const runPatterns = (pattern, options) => __async(void 0, null, function* () {
|
|
|
142
151
|
return;
|
|
143
152
|
}
|
|
144
153
|
const from2 = globEntry.path;
|
|
145
|
-
const absoluteFrom2 = import_path.default.resolve(
|
|
154
|
+
const absoluteFrom2 = import_path.default.resolve(targetPattern.context, from2);
|
|
146
155
|
const to = import_path.default.normalize(
|
|
147
|
-
typeof
|
|
156
|
+
typeof targetPattern.to !== "undefined" ? targetPattern.to : ""
|
|
148
157
|
);
|
|
149
158
|
const toType = import_path.default.extname(to) === "" || to.slice(-1) === import_path.default.sep ? "dir" : "file";
|
|
150
159
|
const relativeFrom = import_path.default.relative(
|
|
151
|
-
(_a2 =
|
|
160
|
+
(_a2 = targetPattern.context) != null ? _a2 : defaultAbsContext,
|
|
152
161
|
absoluteFrom2
|
|
153
162
|
);
|
|
154
163
|
const filename = toType === "dir" ? import_path.default.join(to, relativeFrom) : to;
|
|
155
164
|
const absoluteTo = import_path.default.isAbsolute(filename) ? filename : import_path.default.join(options.outDir, filename);
|
|
165
|
+
if (options.watch) {
|
|
166
|
+
watchMap.set(absoluteFrom2, absoluteTo);
|
|
167
|
+
}
|
|
156
168
|
if (enableCopySync) {
|
|
157
169
|
fs.copySync(absoluteFrom2, absoluteTo);
|
|
158
170
|
} else {
|
|
@@ -160,6 +172,46 @@ const runPatterns = (pattern, options) => __async(void 0, null, function* () {
|
|
|
160
172
|
}
|
|
161
173
|
}));
|
|
162
174
|
});
|
|
175
|
+
const watchCopyFiles = (options, copyConfig) => __async(void 0, null, function* () {
|
|
176
|
+
const { watch, fs, logger, createDebugger } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
177
|
+
const debug = createDebugger("module-tools:copy-watch");
|
|
178
|
+
debug("watchMap", watchMap);
|
|
179
|
+
const { SectionTitleStatus, CopyLogPrefix } = yield Promise.resolve().then(() => __toESM(require("../constants/log")));
|
|
180
|
+
const { watchSectionTitle } = yield Promise.resolve().then(() => __toESM(require("../utils/log")));
|
|
181
|
+
const watchList = Array.from(watchMap.keys());
|
|
182
|
+
debug("watchList", watchList);
|
|
183
|
+
watch(watchList, (_0) => __async(void 0, [_0], function* ({ changedFilePath, changeType }) {
|
|
184
|
+
var _a;
|
|
185
|
+
const result = watchMap.get(changedFilePath);
|
|
186
|
+
if (!result) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const formatFilePath = import_path.default.relative(options.appDirectory, changedFilePath);
|
|
190
|
+
if (changeType === "unlink") {
|
|
191
|
+
fs.remove(result);
|
|
192
|
+
logger.log(
|
|
193
|
+
yield watchSectionTitle(
|
|
194
|
+
CopyLogPrefix,
|
|
195
|
+
SectionTitleStatus.Log,
|
|
196
|
+
`${formatFilePath} removed`
|
|
197
|
+
)
|
|
198
|
+
);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if ((_a = copyConfig == null ? void 0 : copyConfig.options) == null ? void 0 : _a.enableCopySync) {
|
|
202
|
+
fs.copySync(changedFilePath, result);
|
|
203
|
+
} else {
|
|
204
|
+
yield fs.copy(changedFilePath, result);
|
|
205
|
+
}
|
|
206
|
+
logger.log(
|
|
207
|
+
yield watchSectionTitle(
|
|
208
|
+
CopyLogPrefix,
|
|
209
|
+
SectionTitleStatus.Log,
|
|
210
|
+
`${formatFilePath} changed`
|
|
211
|
+
)
|
|
212
|
+
);
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
163
215
|
const copyTask = (buildConfig, options) => __async(void 0, null, function* () {
|
|
164
216
|
var _a;
|
|
165
217
|
const copyConfig = buildConfig.copy;
|
|
@@ -186,9 +238,15 @@ const copyTask = (buildConfig, options) => __async(void 0, null, function* () {
|
|
|
186
238
|
console.error(`copy error: ${e.message}`);
|
|
187
239
|
}
|
|
188
240
|
}
|
|
241
|
+
if (options.watch) {
|
|
242
|
+
yield watchCopyFiles(options, copyConfig);
|
|
243
|
+
}
|
|
189
244
|
});
|
|
190
245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
191
246
|
0 && (module.exports = {
|
|
192
247
|
copyTask,
|
|
193
|
-
runPatterns
|
|
248
|
+
runPatterns,
|
|
249
|
+
watchCopyFiles
|
|
194
250
|
});
|
|
251
|
+
|
|
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CAAY,YAAZ,mBAAqB,gBAAgB;AACvC,SAAG,SAAS,iBAAiB,MAAM;AAAA,IACrC,OAAO;AACL,YAAM,GAAG,KAAK,iBAAiB,MAAM;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,QACJ;AAAA,QACA,mBAAmB;AAAA,QACnB,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF,EAAC;AACH;AAEO,MAAM,WAAW,CACtB,aACA,YAIG;AA9ML;AA+ME,QAAM,aAAa,YAAY;AAE/B,MAAI,CAAC,WAAW,YAAY,WAAW,SAAS,WAAW,GAAG;AAC5D;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,KAAK,IAAI,MAAM,6CAAO,sBAAsB;AAC7D,QAAM,gBAAc,8CAAY,YAAZ,mBAAqB,gBAAe;AACxD,MAAI;AACF,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,CAAM,eAAc;AA1N1B;AA2NQ,cAAM,YAAY,YAAY,iCACzB,UADyB;AAAA,UAE5B,iBAAgBC,iBAAW,YAAX,oBAAoB;AAAA,UACpC,QAAQ,YAAY;AAAA,UACpB,gBAAgB,YAAY;AAAA,QAC9B,EAAC;AAAA,MACH;AAAA,MACA,EAAE,YAAY;AAAA,IAChB;AAAA,EACF,SAAS,GAAP;AACA,QAAI,aAAa,OAAO;AACtB,cAAQ,MAAM,eAAe,EAAE,SAAS;AAAA,IAC1C;AAAA,EACF;AACA,MAAI,QAAQ,OAAO;AACjB,UAAM,eAAe,SAAS,UAAU;AAAA,EAC1C;AACF;;;;;;;","names":["from","absoluteFrom","_a"],"sources":["../../src/builder/copy.ts"],"sourcesContent":["import path from 'path';\nimport type { CopyOptions, CopyPattern } from '../types/copy';\nimport type { BaseBuildConfig } from '../types/config';\n\nconst watchMap = new Map<string, string>();\n\nexport const runPatterns = async (\n pattern: CopyPattern,\n options: {\n appDirectory: string;\n enableCopySync?: boolean;\n outDir: string;\n defaultContext: string;\n watch?: boolean;\n },\n) => {\n const { fs, fastGlob, globby } = await import('@modern-js/utils');\n const { default: normalizePath } = await import(\n '../../compiled/normalize-path'\n );\n const { appDirectory, enableCopySync = false } = options;\n const { from, globOptions = {} } = pattern;\n const targetPattern: CopyPattern = { ...pattern };\n const normalizedFrom = path.normalize(from);\n const defaultAbsContext = options.defaultContext;\n\n // when context is relative path\n if (typeof pattern.context === 'string') {\n targetPattern.context = path.isAbsolute(pattern.context)\n ? pattern.context\n : path.join(appDirectory, pattern.context);\n } else {\n targetPattern.context = defaultAbsContext;\n }\n\n let absoluteFrom;\n if (path.isAbsolute(normalizedFrom)) {\n absoluteFrom = normalizedFrom;\n } else {\n absoluteFrom = path.resolve(targetPattern.context, normalizedFrom);\n }\n\n let stats;\n try {\n stats = await fs.stat(absoluteFrom);\n } catch (error) {\n // Do Nothing\n }\n\n let fromType: 'file' | 'dir' | 'glob';\n if (stats) {\n if (stats.isDirectory()) {\n fromType = 'dir';\n } else if (stats.isFile()) {\n fromType = 'file';\n } else {\n fromType = 'glob';\n }\n } else {\n fromType = 'glob';\n }\n\n let glob;\n\n switch (fromType) {\n case 'dir':\n targetPattern.context = absoluteFrom;\n glob = path.posix.join(\n fastGlob.escapePath(normalizePath(path.resolve(absoluteFrom))),\n '**/*',\n );\n absoluteFrom = path.join(absoluteFrom, '**/*');\n\n if (typeof globOptions.dot === 'undefined') {\n globOptions.dot = true;\n }\n break;\n case 'file':\n targetPattern.context = path.dirname(absoluteFrom);\n glob = fastGlob.escapePath(normalizePath(path.resolve(absoluteFrom)));\n\n if (typeof globOptions.dot === 'undefined') {\n globOptions.dot = true;\n }\n break;\n case 'glob':\n default: {\n glob = path.isAbsolute(from)\n ? from\n : path.posix.join(\n fastGlob.escapePath(\n normalizePath(\n path.resolve(targetPattern.context ?? appDirectory),\n ),\n ),\n from,\n );\n }\n }\n\n const globEntries = await globby(glob, {\n ...{ followSymbolicLinks: true },\n ...(targetPattern.globOptions || {}),\n cwd: targetPattern.context,\n objectMode: true,\n });\n const { default: pMap } = await import('../../compiled/p-map');\n pMap(globEntries, async globEntry => {\n if (!globEntry.dirent.isFile()) {\n return;\n }\n\n const from = globEntry.path;\n const absoluteFrom = path.resolve(targetPattern.context!, from);\n const to = path.normalize(\n typeof targetPattern.to !== 'undefined' ? targetPattern.to : '',\n );\n const toType =\n path.extname(to) === '' || to.slice(-1) === path.sep ? 'dir' : 'file';\n\n const relativeFrom = path.relative(\n targetPattern.context ?? defaultAbsContext,\n absoluteFrom,\n );\n\n const filename = toType === 'dir' ? path.join(to, relativeFrom) : to;\n\n const absoluteTo = path.isAbsolute(filename)\n ? filename\n : path.join(options.outDir, filename);\n\n if (options.watch) {\n watchMap.set(absoluteFrom, absoluteTo);\n }\n\n if (enableCopySync) {\n fs.copySync(absoluteFrom, absoluteTo);\n } else {\n await fs.copy(absoluteFrom, absoluteTo);\n }\n });\n};\n\nexport const watchCopyFiles = async (\n options: {\n appDirectory: string;\n },\n copyConfig: CopyOptions,\n) => {\n const { watch, fs, logger, createDebugger } = await import(\n '@modern-js/utils'\n );\n const debug = createDebugger('module-tools:copy-watch');\n\n debug('watchMap', watchMap);\n\n const { SectionTitleStatus, CopyLogPrefix } = await import(\n '../constants/log'\n );\n const { watchSectionTitle } = await import('../utils/log');\n const watchList = Array.from(watchMap.keys());\n\n debug('watchList', watchList);\n\n watch(watchList, async ({ changedFilePath, changeType }) => {\n const result = watchMap.get(changedFilePath);\n if (!result) {\n return;\n }\n\n const formatFilePath = path.relative(options.appDirectory, changedFilePath);\n\n if (changeType === 'unlink') {\n fs.remove(result);\n logger.log(\n await watchSectionTitle(\n CopyLogPrefix,\n SectionTitleStatus.Log,\n `${formatFilePath} removed`,\n ),\n );\n return;\n }\n\n if (copyConfig?.options?.enableCopySync) {\n fs.copySync(changedFilePath, result);\n } else {\n await fs.copy(changedFilePath, result);\n }\n\n logger.log(\n await watchSectionTitle(\n CopyLogPrefix,\n SectionTitleStatus.Log,\n `${formatFilePath} changed`,\n ),\n );\n });\n};\n\nexport const copyTask = async (\n buildConfig: BaseBuildConfig,\n options: {\n appDirectory: string;\n watch?: boolean;\n },\n) => {\n const copyConfig = buildConfig.copy;\n\n if (!copyConfig.patterns || copyConfig.patterns.length === 0) {\n return;\n }\n\n const { default: pMap } = await import('../../compiled/p-map');\n const concurrency = copyConfig?.options?.concurrency || 100;\n try {\n await pMap(\n copyConfig.patterns,\n async copyOption => {\n await runPatterns(copyOption, {\n ...options,\n enableCopySync: copyConfig.options?.enableCopySync,\n outDir: buildConfig.outDir,\n defaultContext: buildConfig.sourceDir,\n });\n },\n { concurrency },\n );\n } catch (e) {\n if (e instanceof Error) {\n console.error(`copy error: ${e.message}`);\n }\n }\n if (options.watch) {\n await watchCopyFiles(options, copyConfig);\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0B;AAC1B,iBAAuB;;;;;;","names":[],"sources":["../../../src/builder/dts/index.ts"],"sourcesContent":["export { runRollup } from './rollup';\nexport { runTsc } from './tsc';\n"]}
|
|
@@ -34,6 +34,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
34
34
|
return to;
|
|
35
35
|
};
|
|
36
36
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
41
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
42
|
mod
|
|
39
43
|
));
|
|
@@ -91,20 +95,32 @@ const runRollup = (_0, _1) => __async(void 0, [_0, _1], function* (api, { distDi
|
|
|
91
95
|
jsonPlugin(),
|
|
92
96
|
ignoreFiles,
|
|
93
97
|
dtsPlugin({
|
|
98
|
+
// use external to prevent them which come from node_modules from be bundled.
|
|
94
99
|
respectExternal: true,
|
|
95
100
|
compilerOptions: __spreadProps(__spreadValues({
|
|
96
101
|
declarationMap: false,
|
|
97
102
|
skipLibCheck: true,
|
|
103
|
+
// https://github.com/Swatinem/rollup-plugin-dts/issues/143,
|
|
104
|
+
// but it will cause error when bundle ts which import another ts file.
|
|
98
105
|
preserveSymlinks: false
|
|
99
106
|
}, options), {
|
|
107
|
+
// https://github.com/Swatinem/rollup-plugin-dts/issues/127
|
|
108
|
+
composite: false,
|
|
109
|
+
// isAbsolute
|
|
100
110
|
baseUrl,
|
|
111
|
+
// Ensure ".d.ts" modules are generated
|
|
101
112
|
declaration: true,
|
|
113
|
+
// Skip ".js" generation
|
|
102
114
|
noEmit: false,
|
|
103
115
|
emitDeclarationOnly: true,
|
|
116
|
+
// Skip code generation when error occurs
|
|
104
117
|
noEmitOnError: true,
|
|
118
|
+
// Avoid extra work
|
|
105
119
|
checkJs: false,
|
|
120
|
+
// Ensure we can parse the latest code
|
|
106
121
|
target: ts.ScriptTarget.ESNext
|
|
107
|
-
})
|
|
122
|
+
}),
|
|
123
|
+
tsconfig: tsconfigPath
|
|
108
124
|
})
|
|
109
125
|
].filter(Boolean)
|
|
110
126
|
};
|
|
@@ -162,3 +178,5 @@ const runRollup = (_0, _1) => __async(void 0, [_0, _1], function* (api, { distDi
|
|
|
162
178
|
0 && (module.exports = {
|
|
163
179
|
runRollup
|
|
164
180
|
});
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=rollup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAwBV,MAAM,YAAY,CACvB,IACA,OACG,iBAFH,IACA,KACG,WAFH,KACA,EAAE,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/rollup.ts"],"sourcesContent":["import path from 'path';\nimport type {\n InputOptions,\n OutputOptions,\n Plugin,\n RollupWatcher,\n} from '../../../compiled/rollup';\nimport type {\n BaseBuildConfig,\n Input,\n PluginAPI,\n ModuleTools,\n} from '../../types';\n\nexport type { RollupWatcher };\n\ntype Config = {\n distDir: string;\n tsconfigPath: string;\n externals: BaseBuildConfig['externals'];\n input: Input;\n watch: boolean;\n};\n\nexport const runRollup = async (\n api: PluginAPI<ModuleTools>,\n { distDir, tsconfigPath, externals, input, watch }: Config,\n) => {\n const ignoreFiles: Plugin = {\n name: 'ignore-files',\n load(id) {\n if (!/\\.(js|jsx|ts|tsx|json|cts|mts)$/.test(id)) {\n return '';\n }\n return null;\n },\n };\n const ts = await import('typescript');\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n const { options } = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n './',\n );\n\n const { default: jsonPlugin } = await import(\n '../../../compiled/@rollup/plugin-json'\n );\n const { default: dtsPlugin } = await import(\n '../../../compiled/rollup-plugin-dts'\n );\n const baseUrl = path.isAbsolute(options.baseUrl || '.')\n ? options.baseUrl\n : path.join(path.dirname(tsconfigPath), options.baseUrl || '.');\n const inputConfig: InputOptions = {\n input,\n external: externals,\n plugins: [\n jsonPlugin(),\n ignoreFiles,\n dtsPlugin({\n // use external to prevent them which come from node_modules from be bundled.\n respectExternal: true,\n compilerOptions: {\n declarationMap: false,\n skipLibCheck: true,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/143,\n // but it will cause error when bundle ts which import another ts file.\n preserveSymlinks: false,\n ...options,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/127\n composite: false,\n // isAbsolute\n baseUrl,\n // Ensure \".d.ts\" modules are generated\n declaration: true,\n // Skip \".js\" generation\n noEmit: false,\n emitDeclarationOnly: true,\n // Skip code generation when error occurs\n noEmitOnError: true,\n // Avoid extra work\n checkJs: false,\n // Ensure we can parse the latest code\n target: ts.ScriptTarget.ESNext,\n },\n tsconfig: tsconfigPath,\n }),\n ].filter(Boolean),\n };\n const outputConfig: OutputOptions = {\n dir: distDir,\n format: 'esm',\n exports: 'named',\n };\n if (watch) {\n const { watch } = await import('../../../compiled/rollup');\n const { watchSectionTitle } = await import('../../utils/log');\n const { SectionTitleStatus, BundleDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const runner = api.useHookRunners();\n const watcher = watch({\n ...inputConfig,\n plugins: inputConfig.plugins,\n output: outputConfig,\n }).on('event', async event => {\n if (event.code === 'START') {\n console.info(\n await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log),\n );\n } else if (event.code === 'BUNDLE_END') {\n console.info(\n await watchSectionTitle(\n BundleDtsLogPrefix,\n SectionTitleStatus.Success,\n ),\n );\n runner.buildWatchDts({ buildType: 'bundle' });\n } else if (event.code === 'ERROR') {\n // this is dts rollup plugin bug, error not complete message\n }\n });\n return watcher;\n } else {\n try {\n const { rollup } = await import('../../../compiled/rollup');\n const { addRollupChunk } = await import('../../utils/print');\n const bundle = await rollup(inputConfig);\n const rollupOutput = await bundle.write(outputConfig);\n const { appDirectory } = api.useAppContext();\n addRollupChunk(rollupOutput, appDirectory, outputConfig.dir!);\n return bundle;\n } catch (e) {\n if (e instanceof Error) {\n const { InternalDTSError } = await import('../../error');\n throw new InternalDTSError(e, {\n buildType: 'bundle',\n });\n }\n throw e;\n }\n }\n};\n"]}
|
package/dist/builder/dts/tsc.js
CHANGED
|
@@ -34,6 +34,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
34
34
|
return to;
|
|
35
35
|
};
|
|
36
36
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
41
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
42
|
mod
|
|
39
43
|
));
|
|
@@ -112,7 +116,9 @@ const generatorDts = (api, config) => __async(void 0, null, function* () {
|
|
|
112
116
|
[
|
|
113
117
|
"-p",
|
|
114
118
|
result.tempTsconfigPath,
|
|
119
|
+
/* Required parameter, use it stdout have color */
|
|
115
120
|
"--pretty",
|
|
121
|
+
// https://github.com/microsoft/TypeScript/issues/21824
|
|
116
122
|
"--preserveWatchOutput",
|
|
117
123
|
...watchParams
|
|
118
124
|
],
|
|
@@ -153,3 +159,5 @@ const runTsc = (api, config) => __async(void 0, null, function* () {
|
|
|
153
159
|
getProjectTsconfig,
|
|
154
160
|
runTsc
|
|
155
161
|
});
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=tsc.js.map
|