@cocos/ccbuild 2.0.3-alpha.0 → 2.0.3-alpha.10

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 (98) 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 +1 -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 +32 -44
  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/engine-ts/plugins/node-module-loader.d.ts.map +1 -1
  38. package/modules/build-engine/lib/engine-ts/plugins/node-module-loader.js +3 -2
  39. package/modules/build-engine/lib/engine-ts/plugins/node-module-loader.js.map +1 -1
  40. package/modules/build-engine/lib/index.d.ts +98 -86
  41. package/modules/build-engine/lib/index.d.ts.map +1 -1
  42. package/modules/build-engine/lib/index.js +69 -38
  43. package/modules/build-engine/lib/index.js.map +1 -1
  44. package/modules/dts-bundler/lib/index.d.ts +5 -0
  45. package/modules/dts-bundler/lib/index.d.ts.map +1 -0
  46. package/modules/dts-bundler/lib/index.js +344 -0
  47. package/modules/dts-bundler/lib/index.js.map +1 -0
  48. package/modules/modularize/lib/index.d.ts +3 -20
  49. package/modules/modularize/lib/index.d.ts.map +1 -1
  50. package/modules/modularize/lib/index.js +20 -75
  51. package/modules/modularize/lib/index.js.map +1 -1
  52. package/modules/modularize/lib/module-config.d.ts +134 -0
  53. package/modules/modularize/lib/module-config.d.ts.map +1 -0
  54. package/modules/modularize/lib/module-config.js +6 -0
  55. package/modules/modularize/lib/module-config.js.map +1 -0
  56. package/modules/modularize/lib/module-config.schema.json +425 -0
  57. package/modules/modularize/lib/module-query.d.ts +55 -0
  58. package/modules/modularize/lib/module-query.d.ts.map +1 -0
  59. package/modules/modularize/lib/module-query.js +207 -0
  60. package/modules/modularize/lib/module-query.js.map +1 -0
  61. package/modules/modularize/lib/platform-config.d.ts +43 -0
  62. package/modules/modularize/lib/platform-config.d.ts.map +1 -0
  63. package/modules/modularize/lib/platform-config.js +52 -0
  64. package/modules/modularize/lib/platform-config.js.map +1 -0
  65. package/modules/stats-query/lib/cc.config.schema.json +216 -0
  66. package/modules/stats-query/lib/config-interface.d.ts +61 -61
  67. package/modules/stats-query/lib/config-interface.js +1 -1
  68. package/modules/stats-query/lib/config-interface.js.map +1 -1
  69. package/modules/stats-query/lib/index.d.ts +62 -73
  70. package/modules/stats-query/lib/index.d.ts.map +1 -1
  71. package/modules/stats-query/lib/index.js +43 -38
  72. package/modules/stats-query/lib/index.js.map +1 -1
  73. package/modules/transformer/lib/babel/plugins.d.ts +1 -0
  74. package/modules/transformer/lib/babel/plugins.d.ts.map +1 -1
  75. package/modules/transformer/lib/babel/plugins.js +2 -4
  76. package/modules/transformer/lib/babel/plugins.js.map +1 -1
  77. package/modules/transformer/lib/index.d.ts +2 -1
  78. package/modules/transformer/lib/index.d.ts.map +1 -1
  79. package/modules/transformer/lib/index.js +4 -2
  80. package/modules/transformer/lib/index.js.map +1 -1
  81. package/modules/transformer/lib/typescript/index.d.ts +2 -0
  82. package/modules/transformer/lib/typescript/index.d.ts.map +1 -0
  83. package/modules/transformer/lib/typescript/index.js +39 -0
  84. package/modules/transformer/lib/typescript/index.js.map +1 -0
  85. package/modules/transformer/static/types-polyfill.d.ts +18 -0
  86. package/modules/utils/lib/index.d.ts +3 -1
  87. package/modules/utils/lib/index.d.ts.map +1 -1
  88. package/modules/utils/lib/index.js +61 -4
  89. package/modules/utils/lib/index.js.map +1 -1
  90. package/modules/utils/lib/path.d.ts +5 -0
  91. package/modules/utils/lib/path.d.ts.map +1 -1
  92. package/modules/utils/lib/path.js +21 -4
  93. package/modules/utils/lib/path.js.map +1 -1
  94. package/package.json +26 -20
  95. package/static/helper-dynamic-constants.txt +13 -13
  96. package/static/helper-file-decorator.ts +20 -20
  97. package/static/helper-global-exporter.txt +8 -8
  98. 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.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 7bb3ea2: fix: getAllModules in ModuleQuery
8
+
9
+ ## 2.0.3-alpha.9
10
+
11
+ ### Patch Changes
12
+
13
+ - 2c600f4: add peerDependencies for module config
14
+ - 08afa0f: feat: support buildDTS
15
+ - 354cc12: feat: support cc.editor.d.ts build
16
+
17
+ ## 2.0.3-alpha.8
18
+
19
+ ### Patch Changes
20
+
21
+ - a294f8b: remove dep of Modularize on StatsQuery
22
+ - fe1f559: feat: support enumerateDependentAssets and remove deprecation of enumerateDependentChunks
23
+ - 17fecf1: workflow: support gen module graph
24
+
25
+ ## 2.0.3-alpha.7
26
+
27
+ ### Patch Changes
28
+
29
+ - be67053: remove api-extractor and use tfig as api report tool
30
+ - 5cf707e: feat: support editor internal export
31
+ - fix: build ts engine with asm.js in CJS
32
+ - be67053: designed module config schema
33
+ - be67053: fix: add babel types
34
+ - be67053: add Modularize module to support engine modularization
35
+
36
+ ## 2.0.3-alpha.6
37
+
38
+ ### Patch Changes
39
+
40
+ - 2c4e7a8: support typescript in Transformer module
41
+
42
+ ## 2.0.3-alpha.5
43
+
44
+ ### Patch Changes
45
+
46
+ - optimize: remove eslint deps on ts engine builder
47
+
48
+ ## 2.0.3-alpha.4
49
+
50
+ ### Patch Changes
51
+
52
+ - 673cb2d: fix: type error in CCBuildTsFieldDecoratorHelper
53
+
54
+ ## 2.0.3-alpha.3
55
+
56
+ ### Patch Changes
57
+
58
+ - fix: dts files copy in naitve/external
59
+
60
+ ## 2.0.3-alpha.2
61
+
62
+ ### Patch Changes
63
+
64
+ - a8463a2: fix: circular reference && type merge && handle cache
65
+
66
+ ## 2.0.3-alpha.1
67
+
68
+ ### Patch Changes
69
+
70
+ - 5df4c85: fix: circular reference while building ts engine
71
+
3
72
  ## 2.0.3-alpha.0
4
73
 
5
74
  ### Patch Changes
@@ -36,3 +105,203 @@ Thu, 13 Jul 2023 15:30:27 GMT
36
105
 
37
106
  - fix dts types && fix fs-extra version
38
107
  - fix build ts engine with intrinsic flag
108
+
109
+ ## 1.1.20
110
+
111
+ ### Patch Changes
112
+
113
+ - 1cb3389: dperecate: build engine loose option
114
+
115
+ ## 1.1.19
116
+
117
+ ### Patch Changes
118
+
119
+ - bb5f1e5: fix: async bundle external wasm module
120
+
121
+ ## 1.1.18
122
+
123
+ ### Patch Changes
124
+
125
+ - 84d16d6: feat: wasm subpackage support umd
126
+
127
+ ## 1.1.17
128
+
129
+ ### Patch Changes
130
+
131
+ - fix: enumerateAllDependents doesn't resolve featureUnits' dependent chunks' dependent asset
132
+
133
+ ## 1.1.16
134
+
135
+ ### Patch Changes
136
+
137
+ - 40da2c0: fix: use inline dynamic imports on OH platform
138
+
139
+ ## 1.1.15
140
+
141
+ ### Patch Changes
142
+
143
+ - downgrade glob to fix compability with node14
144
+
145
+ ## 1.1.14
146
+
147
+ ### Patch Changes
148
+
149
+ - 1a46941: feat: support wasmSubpackage options on externalWasmLoader
150
+
151
+ ## 1.1.13
152
+
153
+ ### Patch Changes
154
+
155
+ - feat: support constant WASM_SUBPACKAGE
156
+
157
+ ## 1.1.12
158
+
159
+ ### Patch Changes
160
+
161
+ - 84a40ac: feat: support load wasm.fallback module && WASM_FALLBACK constant
162
+
163
+ ## 1.1.11
164
+
165
+ ### Patch Changes
166
+
167
+ - 58a3a35: feat: support buildEngine.enumerateAllDependents()
168
+
169
+ ## 1.1.10
170
+
171
+ ### Patch Changes
172
+
173
+ - e3c3221: fix: culling bullet wasm on wechat platform
174
+
175
+ ## 1.1.9
176
+
177
+ ### Patch Changes
178
+
179
+ - f7fe86e: feat: support constant CULL_ASM_JS_MODULE
180
+
181
+ ## 1.1.8
182
+
183
+ ### Patch Changes
184
+
185
+ - eb0ede7: fix: change .mem suffix to .bin
186
+
187
+ ## 1.1.7
188
+
189
+ ### Patch Changes
190
+
191
+ - 32d1541: feat: support loading '.js.mem' module
192
+ - 345fc75: fix: downgrade "typescript" version
193
+
194
+ ## 1.1.6
195
+
196
+ ### Patch Changes
197
+
198
+ - fix bullet wasm emit
199
+
200
+ ## 1.1.5
201
+
202
+ ### Patch Changes
203
+
204
+ - caffe4d: add FORCE_BANNING_BULLET_WASM constant, controlled by ammoJsWasm option
205
+
206
+ ## 1.1.4
207
+
208
+ ### Patch Changes
209
+
210
+ - 2aa2d7f: add EDITOR_NOT_IN_PREVIEW dynamic constant
211
+ - 8001c61: Revert "patch: add EDITOR_PREVIEW dynamic constant (#7)"
212
+
213
+ ## 1.1.3
214
+
215
+ ### Patch Changes
216
+
217
+ - 9406d42: add EDITOR_PREVIEW dynamic constant
218
+
219
+ ## 1.1.2
220
+
221
+ ### Patch Changes
222
+
223
+ - d70a215: fix: export `WASM_SUPPORT_MODE` for dynamic const
224
+
225
+ ## 1.1.1
226
+
227
+ ### Patch Changes
228
+
229
+ - fix: use fixed babel version
230
+
231
+ ## 1.1.0
232
+
233
+ ### Minor Changes
234
+
235
+ - 279e42a: feat: support engine WASM module building
236
+
237
+ ### Patch Changes
238
+
239
+ - 6411ef4: feat: support CCBuildTsFieldDecoratorHelper
240
+
241
+ ## 1.0.1-alpha.0
242
+
243
+ ### Patch Changes
244
+
245
+ - d94d769: feat: support CCBuildTsFieldDecoratorHelper
246
+
247
+ ## 1.0.0
248
+
249
+ ### Major Changes
250
+
251
+ - e49f97e: integrate build js engine
252
+
253
+ ### Patch Changes
254
+
255
+ - e49f97e: revert @rollup/plugin-node-resolve version to fix rollup issue https://github.com/rollup/plugins/issues/1464
256
+ - e49f97e: fix wrong rullup version deps
257
+ - d2b5b77: support keepTypes options
258
+ - bdea922: change @rollup/plugin-terser to rollup-plugin-terser
259
+ - d2b5b77: make PlatformType for string
260
+ - b2f4116: implement build ts engine
261
+ - 74eb0fc: use build js engine for OH platform
262
+ - remove assert that build js engine should be in BUILD mode
263
+ - ed9a9db: fix @rollup/plugin-json deps for editor-extension install
264
+ - 3ac56fa: change keepTypes to preserveType option
265
+
266
+ ## 1.0.0-alpha.13
267
+
268
+ ### Patch Changes
269
+
270
+ - change keepTypes to preserveType option
271
+
272
+ ## 1.0.0-alpha.12
273
+
274
+ ### Patch Changes
275
+
276
+ - support keepTypes options
277
+ - make PlatformType for string
278
+ - b2f4116: implement build ts engine
279
+
280
+ ## 1.0.0-alpha.11
281
+
282
+ ### Patch Changes
283
+
284
+ - use build js engine for OH platform
285
+
286
+ ## 1.0.0-alpha.10
287
+
288
+ ### Patch Changes
289
+
290
+ - change @rollup/plugin-terser to rollup-plugin-terser
291
+
292
+ ## 1.0.0-alpha.9
293
+
294
+ ### Patch Changes
295
+
296
+ - fix @rollup/plugin-json deps for editor-extension install
297
+
298
+ ## 1.0.0-alpha.8
299
+
300
+ ### Major Changes
301
+
302
+ - e49f97e: integrate build js engine
303
+
304
+ ### Patch Changes
305
+
306
+ - e49f97e: revert @rollup/plugin-node-resolve version to fix rollup issue https://github.com/rollup/plugins/issues/1464
307
+ - 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
+ }