@cocos/ccbuild 2.0.3-alpha.1 → 2.0.3-alpha.11

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 (95) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/README.md +16 -37
  3. package/lib/src/index.d.ts +5 -1
  4. package/lib/src/index.d.ts.map +1 -1
  5. package/lib/src/index.js +5 -1
  6. package/lib/src/index.js.map +1 -1
  7. package/modules/build-engine/lib/build-dts.d.ts +7 -0
  8. package/modules/build-engine/lib/build-dts.d.ts.map +1 -0
  9. package/modules/build-engine/lib/build-dts.js +297 -0
  10. package/modules/build-engine/lib/build-dts.js.map +1 -0
  11. package/modules/build-engine/lib/engine-js/index.d.ts.map +1 -1
  12. package/modules/build-engine/lib/engine-js/index.js +11 -2
  13. package/modules/build-engine/lib/engine-js/index.js.map +1 -1
  14. package/modules/build-engine/lib/engine-js/rollup-plugins/external-wasm-loader.d.ts +33 -33
  15. package/modules/build-engine/lib/engine-js/rollup-plugins/external-wasm-loader.d.ts.map +1 -1
  16. package/modules/build-engine/lib/engine-js/rollup-plugins/external-wasm-loader.js +72 -43
  17. package/modules/build-engine/lib/engine-js/rollup-plugins/external-wasm-loader.js.map +1 -1
  18. package/modules/build-engine/lib/engine-js/rollup-plugins/module-query-plugin.d.ts +4 -0
  19. package/modules/build-engine/lib/engine-js/rollup-plugins/module-query-plugin.d.ts.map +1 -0
  20. package/modules/build-engine/lib/engine-js/rollup-plugins/module-query-plugin.js +43 -0
  21. package/modules/build-engine/lib/engine-js/rollup-plugins/module-query-plugin.js.map +1 -0
  22. package/modules/build-engine/lib/engine-js/rollup-plugins/ts-paths.d.ts.map +1 -1
  23. package/modules/build-engine/lib/engine-js/rollup-plugins/ts-paths.js +8 -7
  24. package/modules/build-engine/lib/engine-js/rollup-plugins/ts-paths.js.map +1 -1
  25. package/modules/build-engine/lib/engine-ts/engine-builder.d.ts +0 -1
  26. package/modules/build-engine/lib/engine-ts/engine-builder.d.ts.map +1 -1
  27. package/modules/build-engine/lib/engine-ts/engine-builder.js +28 -47
  28. package/modules/build-engine/lib/engine-ts/engine-builder.js.map +1 -1
  29. package/modules/build-engine/lib/engine-ts/plugins/external-wasm-loader.d.ts.map +1 -1
  30. package/modules/build-engine/lib/engine-ts/plugins/external-wasm-loader.js +20 -3
  31. package/modules/build-engine/lib/engine-ts/plugins/external-wasm-loader.js.map +1 -1
  32. package/modules/build-engine/lib/engine-ts/plugins/interface.d.ts +14 -14
  33. package/modules/build-engine/lib/engine-ts/plugins/module-query-plugin.d.ts +3 -0
  34. package/modules/build-engine/lib/engine-ts/plugins/module-query-plugin.d.ts.map +1 -0
  35. package/modules/build-engine/lib/engine-ts/plugins/module-query-plugin.js +52 -0
  36. package/modules/build-engine/lib/engine-ts/plugins/module-query-plugin.js.map +1 -0
  37. package/modules/build-engine/lib/index.d.ts +98 -86
  38. package/modules/build-engine/lib/index.d.ts.map +1 -1
  39. package/modules/build-engine/lib/index.js +69 -38
  40. package/modules/build-engine/lib/index.js.map +1 -1
  41. package/modules/dts-bundler/lib/index.d.ts +5 -0
  42. package/modules/dts-bundler/lib/index.d.ts.map +1 -0
  43. package/modules/dts-bundler/lib/index.js +344 -0
  44. package/modules/dts-bundler/lib/index.js.map +1 -0
  45. package/modules/modularize/lib/index.d.ts +3 -20
  46. package/modules/modularize/lib/index.d.ts.map +1 -1
  47. package/modules/modularize/lib/index.js +20 -75
  48. package/modules/modularize/lib/index.js.map +1 -1
  49. package/modules/modularize/lib/module-config.d.ts +134 -0
  50. package/modules/modularize/lib/module-config.d.ts.map +1 -0
  51. package/modules/modularize/lib/module-config.js +6 -0
  52. package/modules/modularize/lib/module-config.js.map +1 -0
  53. package/modules/modularize/lib/module-config.schema.json +425 -0
  54. package/modules/modularize/lib/module-query.d.ts +55 -0
  55. package/modules/modularize/lib/module-query.d.ts.map +1 -0
  56. package/modules/modularize/lib/module-query.js +212 -0
  57. package/modules/modularize/lib/module-query.js.map +1 -0
  58. package/modules/modularize/lib/platform-config.d.ts +43 -0
  59. package/modules/modularize/lib/platform-config.d.ts.map +1 -0
  60. package/modules/modularize/lib/platform-config.js +52 -0
  61. package/modules/modularize/lib/platform-config.js.map +1 -0
  62. package/modules/stats-query/lib/cc.config.schema.json +216 -0
  63. package/modules/stats-query/lib/config-interface.d.ts +61 -61
  64. package/modules/stats-query/lib/config-interface.js +1 -1
  65. package/modules/stats-query/lib/config-interface.js.map +1 -1
  66. package/modules/stats-query/lib/index.d.ts +62 -73
  67. package/modules/stats-query/lib/index.d.ts.map +1 -1
  68. package/modules/stats-query/lib/index.js +43 -38
  69. package/modules/stats-query/lib/index.js.map +1 -1
  70. package/modules/transformer/lib/babel/plugins.d.ts +1 -0
  71. package/modules/transformer/lib/babel/plugins.d.ts.map +1 -1
  72. package/modules/transformer/lib/babel/plugins.js +2 -4
  73. package/modules/transformer/lib/babel/plugins.js.map +1 -1
  74. package/modules/transformer/lib/index.d.ts +2 -1
  75. package/modules/transformer/lib/index.d.ts.map +1 -1
  76. package/modules/transformer/lib/index.js +4 -2
  77. package/modules/transformer/lib/index.js.map +1 -1
  78. package/modules/transformer/lib/typescript/index.d.ts +2 -0
  79. package/modules/transformer/lib/typescript/index.d.ts.map +1 -0
  80. package/modules/transformer/lib/typescript/index.js +39 -0
  81. package/modules/transformer/lib/typescript/index.js.map +1 -0
  82. package/modules/transformer/static/types-polyfill.d.ts +18 -0
  83. package/modules/utils/lib/index.d.ts +3 -1
  84. package/modules/utils/lib/index.d.ts.map +1 -1
  85. package/modules/utils/lib/index.js +61 -4
  86. package/modules/utils/lib/index.js.map +1 -1
  87. package/modules/utils/lib/path.d.ts +5 -0
  88. package/modules/utils/lib/path.d.ts.map +1 -1
  89. package/modules/utils/lib/path.js +21 -4
  90. package/modules/utils/lib/path.js.map +1 -1
  91. package/package.json +26 -20
  92. package/static/helper-dynamic-constants.txt +13 -13
  93. package/static/helper-file-decorator.ts +20 -20
  94. package/static/helper-global-exporter.txt +8 -8
  95. package/static/lib.dom.d.ts +2330 -2330
package/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Change Log - @cocos/ccbuild
2
2
 
3
+ ## 2.0.3-alpha.11
4
+
5
+ ### Patch Changes
6
+
7
+ - optimize: get all modules with node exporting package.json
8
+
9
+ ## 2.0.3-alpha.10
10
+
11
+ ### Patch Changes
12
+
13
+ - 7bb3ea2: fix: getAllModules in ModuleQuery
14
+
15
+ ## 2.0.3-alpha.9
16
+
17
+ ### Patch Changes
18
+
19
+ - 2c600f4: add peerDependencies for module config
20
+ - 08afa0f: feat: support buildDTS
21
+ - 354cc12: feat: support cc.editor.d.ts build
22
+
23
+ ## 2.0.3-alpha.8
24
+
25
+ ### Patch Changes
26
+
27
+ - a294f8b: remove dep of Modularize on StatsQuery
28
+ - fe1f559: feat: support enumerateDependentAssets and remove deprecation of enumerateDependentChunks
29
+ - 17fecf1: workflow: support gen module graph
30
+
31
+ ## 2.0.3-alpha.7
32
+
33
+ ### Patch Changes
34
+
35
+ - be67053: remove api-extractor and use tfig as api report tool
36
+ - 5cf707e: feat: support editor internal export
37
+ - fix: build ts engine with asm.js in CJS
38
+ - be67053: designed module config schema
39
+ - be67053: fix: add babel types
40
+ - be67053: add Modularize module to support engine modularization
41
+
42
+ ## 2.0.3-alpha.6
43
+
44
+ ### Patch Changes
45
+
46
+ - 2c4e7a8: support typescript in Transformer module
47
+
48
+ ## 2.0.3-alpha.5
49
+
50
+ ### Patch Changes
51
+
52
+ - optimize: remove eslint deps on ts engine builder
53
+
54
+ ## 2.0.3-alpha.4
55
+
56
+ ### Patch Changes
57
+
58
+ - 673cb2d: fix: type error in CCBuildTsFieldDecoratorHelper
59
+
60
+ ## 2.0.3-alpha.3
61
+
62
+ ### Patch Changes
63
+
64
+ - fix: dts files copy in naitve/external
65
+
66
+ ## 2.0.3-alpha.2
67
+
68
+ ### Patch Changes
69
+
70
+ - a8463a2: fix: circular reference && type merge && handle cache
71
+
3
72
  ## 2.0.3-alpha.1
4
73
 
5
74
  ### Patch Changes
@@ -42,3 +111,203 @@ Thu, 13 Jul 2023 15:30:27 GMT
42
111
 
43
112
  - fix dts types && fix fs-extra version
44
113
  - fix build ts engine with intrinsic flag
114
+
115
+ ## 1.1.20
116
+
117
+ ### Patch Changes
118
+
119
+ - 1cb3389: dperecate: build engine loose option
120
+
121
+ ## 1.1.19
122
+
123
+ ### Patch Changes
124
+
125
+ - bb5f1e5: fix: async bundle external wasm module
126
+
127
+ ## 1.1.18
128
+
129
+ ### Patch Changes
130
+
131
+ - 84d16d6: feat: wasm subpackage support umd
132
+
133
+ ## 1.1.17
134
+
135
+ ### Patch Changes
136
+
137
+ - fix: enumerateAllDependents doesn't resolve featureUnits' dependent chunks' dependent asset
138
+
139
+ ## 1.1.16
140
+
141
+ ### Patch Changes
142
+
143
+ - 40da2c0: fix: use inline dynamic imports on OH platform
144
+
145
+ ## 1.1.15
146
+
147
+ ### Patch Changes
148
+
149
+ - downgrade glob to fix compability with node14
150
+
151
+ ## 1.1.14
152
+
153
+ ### Patch Changes
154
+
155
+ - 1a46941: feat: support wasmSubpackage options on externalWasmLoader
156
+
157
+ ## 1.1.13
158
+
159
+ ### Patch Changes
160
+
161
+ - feat: support constant WASM_SUBPACKAGE
162
+
163
+ ## 1.1.12
164
+
165
+ ### Patch Changes
166
+
167
+ - 84a40ac: feat: support load wasm.fallback module && WASM_FALLBACK constant
168
+
169
+ ## 1.1.11
170
+
171
+ ### Patch Changes
172
+
173
+ - 58a3a35: feat: support buildEngine.enumerateAllDependents()
174
+
175
+ ## 1.1.10
176
+
177
+ ### Patch Changes
178
+
179
+ - e3c3221: fix: culling bullet wasm on wechat platform
180
+
181
+ ## 1.1.9
182
+
183
+ ### Patch Changes
184
+
185
+ - f7fe86e: feat: support constant CULL_ASM_JS_MODULE
186
+
187
+ ## 1.1.8
188
+
189
+ ### Patch Changes
190
+
191
+ - eb0ede7: fix: change .mem suffix to .bin
192
+
193
+ ## 1.1.7
194
+
195
+ ### Patch Changes
196
+
197
+ - 32d1541: feat: support loading '.js.mem' module
198
+ - 345fc75: fix: downgrade "typescript" version
199
+
200
+ ## 1.1.6
201
+
202
+ ### Patch Changes
203
+
204
+ - fix bullet wasm emit
205
+
206
+ ## 1.1.5
207
+
208
+ ### Patch Changes
209
+
210
+ - caffe4d: add FORCE_BANNING_BULLET_WASM constant, controlled by ammoJsWasm option
211
+
212
+ ## 1.1.4
213
+
214
+ ### Patch Changes
215
+
216
+ - 2aa2d7f: add EDITOR_NOT_IN_PREVIEW dynamic constant
217
+ - 8001c61: Revert "patch: add EDITOR_PREVIEW dynamic constant (#7)"
218
+
219
+ ## 1.1.3
220
+
221
+ ### Patch Changes
222
+
223
+ - 9406d42: add EDITOR_PREVIEW dynamic constant
224
+
225
+ ## 1.1.2
226
+
227
+ ### Patch Changes
228
+
229
+ - d70a215: fix: export `WASM_SUPPORT_MODE` for dynamic const
230
+
231
+ ## 1.1.1
232
+
233
+ ### Patch Changes
234
+
235
+ - fix: use fixed babel version
236
+
237
+ ## 1.1.0
238
+
239
+ ### Minor Changes
240
+
241
+ - 279e42a: feat: support engine WASM module building
242
+
243
+ ### Patch Changes
244
+
245
+ - 6411ef4: feat: support CCBuildTsFieldDecoratorHelper
246
+
247
+ ## 1.0.1-alpha.0
248
+
249
+ ### Patch Changes
250
+
251
+ - d94d769: feat: support CCBuildTsFieldDecoratorHelper
252
+
253
+ ## 1.0.0
254
+
255
+ ### Major Changes
256
+
257
+ - e49f97e: integrate build js engine
258
+
259
+ ### Patch Changes
260
+
261
+ - e49f97e: revert @rollup/plugin-node-resolve version to fix rollup issue https://github.com/rollup/plugins/issues/1464
262
+ - e49f97e: fix wrong rullup version deps
263
+ - d2b5b77: support keepTypes options
264
+ - bdea922: change @rollup/plugin-terser to rollup-plugin-terser
265
+ - d2b5b77: make PlatformType for string
266
+ - b2f4116: implement build ts engine
267
+ - 74eb0fc: use build js engine for OH platform
268
+ - remove assert that build js engine should be in BUILD mode
269
+ - ed9a9db: fix @rollup/plugin-json deps for editor-extension install
270
+ - 3ac56fa: change keepTypes to preserveType option
271
+
272
+ ## 1.0.0-alpha.13
273
+
274
+ ### Patch Changes
275
+
276
+ - change keepTypes to preserveType option
277
+
278
+ ## 1.0.0-alpha.12
279
+
280
+ ### Patch Changes
281
+
282
+ - support keepTypes options
283
+ - make PlatformType for string
284
+ - b2f4116: implement build ts engine
285
+
286
+ ## 1.0.0-alpha.11
287
+
288
+ ### Patch Changes
289
+
290
+ - use build js engine for OH platform
291
+
292
+ ## 1.0.0-alpha.10
293
+
294
+ ### Patch Changes
295
+
296
+ - change @rollup/plugin-terser to rollup-plugin-terser
297
+
298
+ ## 1.0.0-alpha.9
299
+
300
+ ### Patch Changes
301
+
302
+ - fix @rollup/plugin-json deps for editor-extension install
303
+
304
+ ## 1.0.0-alpha.8
305
+
306
+ ### Major Changes
307
+
308
+ - e49f97e: integrate build js engine
309
+
310
+ ### Patch Changes
311
+
312
+ - e49f97e: revert @rollup/plugin-node-resolve version to fix rollup issue https://github.com/rollup/plugins/issues/1464
313
+ - e49f97e: fix wrong rullup version deps
package/README.md CHANGED
@@ -1,37 +1,16 @@
1
- # CCBUILD
2
-
3
- The next generation of build tool for Cocos engine.
4
-
5
- # What problems does this build tool solve ?
6
-
7
- - To merge `@editor/quick-compiler` and `@cocos/build-engine`
8
- - To support build cache management
9
- - To support generating ts engine for AOT optimization on Open Harmony
10
- - To support API generation
11
- - To support API report
12
- - To support API document model generation
13
- - To support build modular engine
14
- - More human-friendly log info
15
-
16
- # How to maintain this repo
17
-
18
- Run `npm i` to setup the dev environment.
19
-
20
- ## unit test
21
-
22
- Every time you fix a bug or introduce a new feature to ccbuild, please remember considering to add your unit test into `test` folder, and run `npm test` to make sure all your modification can pass the unit test.
23
-
24
- If you want to update the snapshot, please run `npm test -- -u`.
25
-
26
- ## changelog generation
27
-
28
- We use [changesets](https://github.com/changesets/changesets) to manage all the changelog.
29
- Every time you make a change in the repo, please run `npm run change` to generate a changeset in the folder `.changeset`, this file should be also commit to the repo.
30
-
31
- ## publish
32
-
33
- Please run `npm run version` to publish a version, this command would consume all the changesets in `.changeset` folder.
34
- If you wan't to publish an alpha version, please use `npm run version-alpha`, this command won't consume any of the changesets.
35
-
36
- And finally, run `npm publish` before your npm account got a publish authorization.
37
-
1
+ # CCBUILD
2
+
3
+ The next generation of build tool for Cocos engine.
4
+
5
+ # What problems does this build tool solve ?
6
+
7
+ - To merge `@editor/quick-compiler` and `@cocos/build-engine`
8
+ - To support build cache management
9
+ - To support generating ts engine for AOT optimization on Open Harmony
10
+ - To support API generation
11
+ - To support API report
12
+ - To support API document model generation
13
+ - To support build modular engine
14
+ - More human-friendly log info
15
+
16
+ > [I am a maintainer of this repo](./README_MAINTAIN.md)
@@ -1,5 +1,9 @@
1
1
  import * as Transformer from "../../modules/transformer/lib/index";
2
2
  import * as Bundler from "../../modules/bundler/lib/index";
3
+ import * as Modularize from "../../modules/modularize/lib/index";
4
+ import * as dtsBundler from "../../modules/dts-bundler/lib/index";
3
5
  export { buildEngine } from "../../modules/build-engine/lib/index";
4
6
  export { StatsQuery, ConfigInterface } from "../../modules/stats-query/lib/index";
5
- export { Transformer, Bundler };
7
+ export { Transformer, Bundler };
8
+ export { Modularize };
9
+ export { dtsBundler };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/lib/src/index.js CHANGED
@@ -34,11 +34,15 @@ var __importStar = this && this.__importStar || function (mod) {
34
34
  Object.defineProperty(exports, "__esModule", {
35
35
  value: true
36
36
  });
37
- exports.Bundler = exports.Transformer = exports.ConfigInterface = exports.StatsQuery = exports.buildEngine = void 0;
37
+ exports.dtsBundler = exports.Modularize = exports.Bundler = exports.Transformer = exports.ConfigInterface = exports.StatsQuery = exports.buildEngine = void 0;
38
38
  const Transformer = __importStar(require("../../modules/transformer/lib/index.js"));
39
39
  exports.Transformer = Transformer;
40
40
  const Bundler = __importStar(require("../../modules/bundler/lib/index.js"));
41
41
  exports.Bundler = Bundler;
42
+ const Modularize = __importStar(require("../../modules/modularize/lib/index.js"));
43
+ exports.Modularize = Modularize;
44
+ const dtsBundler = __importStar(require("../../modules/dts-bundler/lib/index.js"));
45
+ exports.dtsBundler = dtsBundler;
42
46
  var build_engine_1 = require("../../modules/build-engine/lib/index.js");
43
47
  Object.defineProperty(exports, "buildEngine", {
44
48
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAoD;AAI3C,kCAAW;AAHpB,0DAA4C;AAGtB,0BAAO;AAF7B,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AACpB,oDAAmE;AAA1D,yGAAA,UAAU,OAAA;AAAE,8GAAA,eAAe,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAoD;AAM3C,kCAAW;AALpB,0DAA4C;AAKtB,0BAAO;AAJ7B,gEAAkD;AAKzC,gCAAU;AAJnB,iEAAmD;AAK1C,gCAAU;AAJnB,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AACpB,oDAAmE;AAA1D,yGAAA,UAAU,OAAA;AAAE,8GAAA,eAAe,OAAA"}
@@ -0,0 +1,7 @@
1
+ export declare function buildDTS(options: {
2
+ engine: string;
3
+ outDir: string;
4
+ withIndex: boolean;
5
+ withExports: boolean;
6
+ withEditorExports: boolean;
7
+ }): Promise<boolean>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-dts.d.ts","sourceRoot":"","sources":["../src/build-dts.ts"],"names":[],"mappings":"AAaA,wBAAsB,QAAQ,CAAE,OAAO,EAAE;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC,OAAO,CAAC,CA2OnB"}
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
20
+ Object.defineProperty(o, "default", {
21
+ enumerable: true,
22
+ value: v
23
+ });
24
+ } : function (o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = this && this.__importStar || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
35
+ function adopt(value) {
36
+ return value instanceof P ? value : new P(function (resolve) {
37
+ resolve(value);
38
+ });
39
+ }
40
+ return new (P || (P = Promise))(function (resolve, reject) {
41
+ function fulfilled(value) {
42
+ try {
43
+ step(generator.next(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ }
48
+ function rejected(value) {
49
+ try {
50
+ step(generator["throw"](value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ }
55
+ function step(result) {
56
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
57
+ }
58
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
59
+ });
60
+ };
61
+ var __importDefault = this && this.__importDefault || function (mod) {
62
+ return mod && mod.__esModule ? mod : {
63
+ "default": mod
64
+ };
65
+ };
66
+ Object.defineProperty(exports, "__esModule", {
67
+ value: true
68
+ });
69
+ exports.buildDTS = void 0;
70
+ const fs_extra_1 = __importDefault(require("fs-extra"));
71
+ const gift = __importStar(require("tfig"));
72
+ const stats_query_1 = require("../../stats-query/lib/index.js");
73
+ const utils_1 = require("../../utils/lib/index.js");
74
+ const transpiler_1 = require("@ccbuild/transpiler");
75
+ var ts = transpiler_1.typescript.core;
76
+ const DEBUG = false;
77
+ const REMOVE_OLD = !DEBUG;
78
+ const RECOMPILE = !DEBUG;
79
+ const REMOVE_UNBUNDLED_CACHE = !DEBUG;
80
+ function buildDTS(options) {
81
+ var _a;
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ console.log(`Typescript version: ${ts.version}`);
84
+ const {
85
+ engine,
86
+ outDir,
87
+ withIndex = true,
88
+ withExports = false,
89
+ withEditorExports = false
90
+ } = options;
91
+ yield fs_extra_1.default.ensureDir(outDir);
92
+ console.debug(`With index: ${withIndex}`);
93
+ console.debug(`With exports: ${withExports}`);
94
+ console.debug(`With editor exports: ${withEditorExports}`);
95
+ const statsQuery = yield stats_query_1.StatsQuery.create(engine);
96
+ const tsConfigPath = statsQuery.tsConfigPath;
97
+ const unbundledOutDir = utils_1.ps.join(outDir, '__before_bundle');
98
+ const parsedCommandLine = ts.getParsedCommandLineOfConfigFile(tsConfigPath, {
99
+ declaration: true,
100
+ noEmit: false,
101
+ emitDeclarationOnly: true,
102
+ outFile: undefined,
103
+ outDir: unbundledOutDir
104
+ }, {
105
+ onUnRecoverableConfigFileDiagnostic: () => {},
106
+ useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
107
+ readDirectory: ts.sys.readDirectory,
108
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
109
+ fileExists: ts.sys.fileExists,
110
+ readFile: ts.sys.readFile
111
+ });
112
+ if (!parsedCommandLine) {
113
+ throw new Error(`Can not get 'parsedCommandLine'.`);
114
+ }
115
+ const unbundledOutDirNormalized = utils_1.ps.resolve(engine, parsedCommandLine.options.outDir);
116
+ console.debug(`Unbundled will write to: ${unbundledOutDirNormalized}`);
117
+ yield fs_extra_1.default.ensureDir(unbundledOutDirNormalized);
118
+ if (REMOVE_OLD) {
119
+ yield fs_extra_1.default.emptyDir(unbundledOutDirNormalized);
120
+ }
121
+ console.log(`Generating...`);
122
+ const featureUnits = statsQuery.getFeatureUnits().filter(m => m !== 'wait-for-ammo-instantiation');
123
+ const editorExportModules = statsQuery.getEditorPublicModules();
124
+ if (RECOMPILE) {
125
+ let fileNames = parsedCommandLine.fileNames;
126
+ if (withEditorExports) {
127
+ fileNames = fileNames.concat(editorExportModules.map(e => statsQuery.getEditorPublicModuleFile(e)));
128
+ }
129
+ const program = ts.createProgram(fileNames, parsedCommandLine.options);
130
+ const emitResult = program.emit(undefined,
131
+ // targetSourceFile
132
+ undefined,
133
+ // writeFile
134
+ undefined,
135
+ // cancellationToken,
136
+ true,
137
+ // emitOnlyDtsFiles
138
+ undefined);
139
+ const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
140
+ for (const diagnostic of allDiagnostics) {
141
+ let printer;
142
+ switch (diagnostic.category) {
143
+ case ts.DiagnosticCategory.Error:
144
+ printer = console.error;
145
+ break;
146
+ case ts.DiagnosticCategory.Warning:
147
+ printer = console.warn;
148
+ break;
149
+ case ts.DiagnosticCategory.Message:
150
+ case ts.DiagnosticCategory.Suggestion:
151
+ default:
152
+ printer = console.log;
153
+ break;
154
+ }
155
+ if (!printer) {
156
+ continue;
157
+ }
158
+ if (diagnostic.file && diagnostic.start !== undefined) {
159
+ const {
160
+ line,
161
+ character
162
+ } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
163
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine);
164
+ printer(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
165
+ } else {
166
+ printer(`${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`);
167
+ }
168
+ }
169
+ }
170
+ // HACK: fix comments generated on top level namespace
171
+ // // TODO:
172
+ // let code = fs.readFileSync(tscOutputDtsFile, 'utf8');
173
+ // const regExpRef = /(\/\/\/ <reference types.*)/g;
174
+ // const matches = code.match(regExpRef);
175
+ // code = code.replace(regExpRef, '');
176
+ // if (matches) {
177
+ // let outputUnbundledCode = matches.join('\n');
178
+ // outputUnbundledCode += '\ndeclare const __skip_reference__: never;\n';
179
+ // outputUnbundledCode += code;
180
+ // fs.outputFileSync(tscOutputDtsFile, outputUnbundledCode, 'utf8');
181
+ // }
182
+ const patchSpineCoreDtsSource = utils_1.ps.join(engine, 'cocos', 'spine', 'lib', 'spine-core.d.ts');
183
+ const patchSpineCoreDtsTarget = utils_1.ps.join(unbundledOutDirNormalized, 'cocos', 'spine', 'lib', 'spine-core.d.ts');
184
+ if (!(yield fs_extra_1.default.pathExists(patchSpineCoreDtsSource))) {
185
+ console.debug(`Does 'cocos/spine/lib/spine-core.d.ts' no longer existed? I have a patch for it.`);
186
+ } else {
187
+ console.debug(`It's ${new Date().toLocaleString()}, we're still doing the hack for spine-core.d.ts`);
188
+ yield fs_extra_1.default.ensureDir(utils_1.ps.dirname(patchSpineCoreDtsTarget));
189
+ yield fs_extra_1.default.copyFile(patchSpineCoreDtsSource, patchSpineCoreDtsTarget);
190
+ }
191
+ const giftInputs = [];
192
+ const types = (_a = parsedCommandLine.options.types) === null || _a === void 0 ? void 0 : _a.map(typeFile => `${typeFile}.d.ts`);
193
+ if (types) {
194
+ for (let file of types) {
195
+ const isBareSpecifier = !file.includes('/');
196
+ if (isBareSpecifier) {
197
+ file = require.resolve(`@types/${file.slice(0, -'.d.ts'.length)}`);
198
+ }
199
+ giftInputs.push(file);
200
+ }
201
+ }
202
+ const listGiftInputs = dir => __awaiter(this, void 0, void 0, function* () {
203
+ for (const file of yield fs_extra_1.default.readdir(dir)) {
204
+ const path = utils_1.ps.join(dir, file);
205
+ // eslint-disable-next-line no-await-in-loop
206
+ const stats = yield fs_extra_1.default.stat(path);
207
+ if (stats.isFile()) {
208
+ giftInputs.push(path);
209
+ } else if (stats.isDirectory()) {
210
+ // eslint-disable-next-line no-await-in-loop
211
+ yield listGiftInputs(path);
212
+ }
213
+ }
214
+ });
215
+ yield listGiftInputs(unbundledOutDirNormalized);
216
+ const giftEntries = {};
217
+ const getModuleNameInTsOutFile = moduleFile => {
218
+ const path = utils_1.ps.relative(statsQuery.path, moduleFile);
219
+ const pathDts = path.replace(/\.ts$/, '.d.ts');
220
+ return utils_1.ps.join(unbundledOutDirNormalized, pathDts);
221
+ };
222
+ if (withExports) {
223
+ for (const exportEntry of featureUnits) {
224
+ giftEntries[exportEntry] = getModuleNameInTsOutFile(statsQuery.getFeatureUnitFile(exportEntry));
225
+ }
226
+ }
227
+ if (withEditorExports) {
228
+ for (const editorExportModule of editorExportModules) {
229
+ giftEntries[editorExportModule] = getModuleNameInTsOutFile(statsQuery.getEditorPublicModuleFile(editorExportModule));
230
+ }
231
+ }
232
+ let ccDtsFile;
233
+ if (withIndex && !withExports) {
234
+ ccDtsFile = utils_1.ps.join(unbundledOutDirNormalized, 'virtual-cc.d.ts');
235
+ giftEntries.cc = ccDtsFile;
236
+ giftInputs.push(ccDtsFile);
237
+ const code = `// Auto-generated\n${statsQuery.evaluateIndexModuleSource(featureUnits, featureUnit => getModuleNameInTsOutFile(statsQuery.getFeatureUnitFile(featureUnit)).replace(/\\/g, '/').replace(/\.d.ts$/, ''))}\n`;
238
+ yield fs_extra_1.default.writeFile(ccDtsFile, code, {
239
+ encoding: 'utf8'
240
+ });
241
+ }
242
+ console.log(`Bundling...`);
243
+ try {
244
+ const indexOutputPath = utils_1.ps.join(outDir, 'cc.d.ts');
245
+ const giftResult = gift.bundle({
246
+ input: giftInputs,
247
+ rootDir: unbundledOutDirNormalized,
248
+ name: 'cc',
249
+ rootModule: 'index',
250
+ entries: giftEntries,
251
+ priority: [...(ccDtsFile ? [ccDtsFile] : []) // Things should be exported to 'cc' as far as possible.
252
+ ],
253
+
254
+ privateJsDocTag: 'engineInternal',
255
+ groups: [{
256
+ test: /^cc\/editor.*$/,
257
+ path: utils_1.ps.join(outDir, 'cc.editor.d.ts')
258
+ }, {
259
+ test: /^cc\/.*$/,
260
+ path: utils_1.ps.join(outDir, 'index.d.ts')
261
+ }, {
262
+ test: /^cc.*$/,
263
+ path: indexOutputPath
264
+ }],
265
+ nonExportedSymbolDistribution: [{
266
+ sourceModule: /cocos\/animation\/marionette/,
267
+ targetModule: 'cc/editor/new-gen-anim'
268
+ }, {
269
+ sourceModule: /.*/,
270
+ targetModule: 'cc'
271
+ }]
272
+ });
273
+ yield Promise.all(giftResult.groups.map(group => __awaiter(this, void 0, void 0, function* () {
274
+ yield fs_extra_1.default.outputFile(group.path, group.code, {
275
+ encoding: 'utf8'
276
+ });
277
+ })));
278
+ if (withIndex && withExports) {
279
+ yield fs_extra_1.default.outputFile(indexOutputPath, buildIndexModule(featureUnits, statsQuery), {
280
+ encoding: 'utf8'
281
+ });
282
+ }
283
+ } catch (error) {
284
+ console.error(error);
285
+ return false;
286
+ } finally {
287
+ if (REMOVE_UNBUNDLED_CACHE) {
288
+ yield fs_extra_1.default.remove(unbundledOutDirNormalized);
289
+ }
290
+ }
291
+ return true;
292
+ });
293
+ }
294
+ exports.buildDTS = buildDTS;
295
+ function buildIndexModule(featureUnits, statsQuery) {
296
+ return `declare module "cc" {\n${statsQuery.evaluateIndexModuleSource(featureUnits).split('\n').map(line => ` ${line}`).join('\n')}\n}`;
297
+ }