@ray-js/builder-mp 1.3.1-beta.7 → 1.3.2

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/lib/build.rjs.js CHANGED
@@ -21,9 +21,7 @@ class RjsBuild {
21
21
  this.options = options;
22
22
  this.parent = parent;
23
23
  this.initRjsBuilder();
24
- parent.hooks.afterCompile.tap(LOG_PREFIX_RJS, () => {
25
- this.run();
26
- });
24
+ this.run();
27
25
  }
28
26
  createWebpackConfig() {
29
27
  const { cwd, output, mini, target } = this.options;
@@ -139,19 +137,21 @@ class RjsBuild {
139
137
  }
140
138
  run() {
141
139
  const cb = this.runOrWatch();
142
- if (this.options.watch) {
143
- if (!this.watcher) {
144
- this.watcher = this.compiler.watch({}, cb);
140
+ this.parent.hooks.afterCompile.tap(LOG_PREFIX_RJS, () => {
141
+ if (this.options.watch) {
142
+ if (!this.watcher) {
143
+ this.watcher = this.compiler.watch({}, cb);
144
+ }
145
+ else {
146
+ this.watcher.close(() => {
147
+ this.watcher = this.compiler.watch({}, cb);
148
+ });
149
+ }
145
150
  }
146
151
  else {
147
- this.watcher.close(() => {
148
- this.watcher = this.compiler.watch({}, cb);
149
- });
152
+ this.compiler.run(cb);
150
153
  }
151
- }
152
- else {
153
- this.compiler.run(cb);
154
- }
154
+ });
155
155
  return this.compiler;
156
156
  }
157
157
  }
@@ -8,6 +8,7 @@ declare class WorkerBuild {
8
8
  private routesConfigFile;
9
9
  constructor(options: CliOptions, parent: webpack.Compiler);
10
10
  private createWebpackConfig;
11
+ private readConfig;
11
12
  private initWorkerBuilder;
12
13
  private runOrWatch;
13
14
  run(): webpack.Compiler;
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  const colors_1 = __importDefault(require("colors"));
9
9
  const shared_1 = require("@ray-js/shared");
10
10
  const legacyExport_1 = require("@ray-core/cli/lib/legacyExport");
11
+ const slash_1 = __importDefault(require("slash"));
11
12
  const builder_1 = require("./builder");
12
13
  const onBuildEnd_1 = __importDefault(require("./plugins/onBuildEnd"));
13
14
  const utils_1 = require("./utils");
@@ -15,6 +16,7 @@ colors_1.default.enable();
15
16
  const extensions = ['.mjs', '.js', '.jsx', '.ts', '.tsx'];
16
17
  const moduleMatcher = new RegExp(`(${extensions.join('|')})$`);
17
18
  const LOG_PREFIX_WORKER = 'build-worker';
19
+ const BUILD_WORKER_PLUGIN = `${LOG_PREFIX_WORKER}-plugin`;
18
20
  const innerPlugins = [(0, onBuildEnd_1.default)(LOG_PREFIX_WORKER)];
19
21
  class WorkerBuild {
20
22
  constructor(options, parent) {
@@ -47,12 +49,13 @@ class WorkerBuild {
47
49
  .options({
48
50
  configFile: path_1.default.resolve(__dirname, './babel/configs/babel.config.js'),
49
51
  });
52
+ const { root } = this.readConfig();
50
53
  config.output
51
54
  .set('filename', '[name].js')
52
55
  .set('libraryTarget', 'commonjs2')
53
56
  .set('clean', false)
54
57
  .set('globalObject', 'worker')
55
- .set('path', output)
58
+ .set('path', root ? path_1.default.join(output, root) : output)
56
59
  .set('publicPath', '/')
57
60
  .end()
58
61
  .optimization.set('runtimeChunk', { name: 'runtime-worker' })
@@ -77,29 +80,39 @@ class WorkerBuild {
77
80
  'process.env.PLATFORM': JSON.stringify(target),
78
81
  },
79
82
  ])
83
+ .end()
84
+ .plugin(BUILD_WORKER_PLUGIN)
85
+ .use(BuildWorkerPlugin)
80
86
  .end()
81
87
  .watchOptions({ aggregateTimeout: 1000 });
82
88
  innerPlugins.forEach((p) => p.configWebpack({ config }));
83
89
  config.resolve.merge(this.parent.options.resolve);
84
90
  return config.toConfig();
85
91
  }
92
+ readConfig() {
93
+ this.routesConfigFile = builder_1.builder.api.searchJSFile('src/routes.config');
94
+ if (!this.routesConfigFile) {
95
+ shared_1.log.error(LOG_PREFIX_WORKER, `missing configuration file (routes.config.{ts|js})`);
96
+ return {};
97
+ }
98
+ delete require.cache[this.routesConfigFile];
99
+ const data = builder_1.builder.api.requireJSFile(this.routesConfigFile).workers || {};
100
+ const { root } = data;
101
+ if (!root) {
102
+ shared_1.log.verbose(LOG_PREFIX_WORKER, `missing prop 'workers' in ${this.routesConfigFile}`);
103
+ return {};
104
+ }
105
+ return data;
106
+ }
86
107
  initWorkerBuilder() {
87
108
  const cfg = this.createWebpackConfig();
88
109
  cfg.entry = () => {
89
- this.routesConfigFile = builder_1.builder.api.searchJSFile('src/routes.config');
90
- if (!this.routesConfigFile) {
91
- shared_1.log.error(LOG_PREFIX_WORKER, `missing configuration file (routes.config.{ts|js})`);
92
- return {};
93
- }
94
- delete require.cache[this.routesConfigFile];
95
- const { root, workers = [] } = builder_1.builder.api.requireJSFile(this.routesConfigFile).workers || {};
96
- if (!root) {
97
- shared_1.log.verbose(LOG_PREFIX_WORKER, `missing prop 'workers' in ${this.routesConfigFile}`);
98
- return {};
99
- }
110
+ const { root, workers = [] } = this.readConfig();
100
111
  const entries = workers.reduce((o, k) => {
101
112
  const { source: rootDir, target, cwd } = this.options;
102
113
  const name = path_1.default.join(root, k);
114
+ const ext = path_1.default.extname(k);
115
+ const outputName = k.replace(new RegExp(`${ext}$`), '');
103
116
  const f = path_1.default.join(cwd, rootDir, name);
104
117
  const m = (0, utils_1.getModuleOfPlatform)(f, {
105
118
  rootDir,
@@ -108,7 +121,7 @@ class WorkerBuild {
108
121
  extensions: ['ts', 'js', 'tsx', 'jsx'],
109
122
  });
110
123
  if (m) {
111
- o[name] = m[1];
124
+ o[outputName] = m[1];
112
125
  }
113
126
  else {
114
127
  shared_1.log.warn(LOG_PREFIX_WORKER, `Can't resolve module ${k} in ${root}`);
@@ -167,9 +180,46 @@ class WorkerBuild {
167
180
  });
168
181
  }
169
182
  else {
170
- this.compiler.run(cb);
183
+ this.parent.hooks.afterCompile.tap(LOG_PREFIX_WORKER, () => {
184
+ this.compiler.run(cb);
185
+ });
171
186
  }
172
187
  return this.compiler;
173
188
  }
174
189
  }
175
190
  exports.default = WorkerBuild;
191
+ const { ConcatSource } = legacyExport_1.customWebpack.sources;
192
+ class BuildWorkerPlugin {
193
+ apply(compiler) {
194
+ compiler.hooks.thisCompilation.tap(BUILD_WORKER_PLUGIN, (compilation) => {
195
+ compilation.hooks.processAssets.tapAsync({
196
+ name: BUILD_WORKER_PLUGIN,
197
+ stage: legacyExport_1.customWebpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
198
+ }, (chunks, callback) => {
199
+ compilation.chunkGroups.forEach((group) => {
200
+ group.chunks.reverse().forEach((chunk) => {
201
+ this.requireChunks(compilation, chunk, group);
202
+ });
203
+ });
204
+ callback();
205
+ });
206
+ });
207
+ }
208
+ requireChunks(compilation, chunk, group) {
209
+ var _a;
210
+ // require 相关的 chunk
211
+ if (chunk.name !== group.name) {
212
+ const requires = [];
213
+ const files = Array.from(chunk.files);
214
+ files.forEach((file) => {
215
+ if (file.endsWith('.js')) {
216
+ const relativePath = (0, slash_1.default)(path_1.default.relative(path_1.default.dirname(group.name), file));
217
+ requires.push(`require('./${relativePath}');\n`);
218
+ }
219
+ });
220
+ const assetPath = group.name + '.js';
221
+ const source = (_a = compilation.assets[assetPath]) !== null && _a !== void 0 ? _a : '';
222
+ compilation.assets[assetPath] = new ConcatSource(...requires, source);
223
+ }
224
+ }
225
+ }
@@ -65,7 +65,9 @@ exports.default = {
65
65
  .options({ builder: builder_1.builder })
66
66
  .end();
67
67
  config.plugin('webpack-define-plugin').tap(([args]) => {
68
- return [Object.assign(Object.assign({}, args), { 'process.env.PLATFORM': JSON.stringify(target) })];
68
+ return [
69
+ Object.assign(Object.assign({}, args), { 'process.env.PLATFORM': JSON.stringify(target), 'process.env.RAY_DEBUG': JSON.stringify(`${process.env.RAY_DEBUG === 'true'}`) }),
70
+ ];
69
71
  });
70
72
  config.resolve.alias.set('@ray-core/ray', path_1.default.dirname(require.resolve('@ray-core/ray/package.json')));
71
73
  config.resolve.alias.set('@ray-js/rjs-for-wechat', path_1.default.dirname(require.resolve('@ray-js/rjs-for-wechat/package.json')));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/builder-mp",
3
- "version": "1.3.1-beta.7",
3
+ "version": "1.3.2",
4
4
  "description": "Ray builder for mini program",
5
5
  "keywords": [
6
6
  "ray"
@@ -21,17 +21,19 @@
21
21
  "test": "jest"
22
22
  },
23
23
  "dependencies": {
24
+ "@babel/plugin-proposal-private-methods": "^7.18.6",
25
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
24
26
  "@babel/template": "^7.16.0",
25
27
  "@babel/traverse": "^7.16.3",
26
28
  "@babel/types": "^7.16.0",
27
- "@ray-core/babel-preset-remax": "^0.3.0-beta.6",
28
- "@ray-core/build-store": "^0.3.0-beta.6",
29
- "@ray-core/cli": "^0.3.0-beta.6",
30
- "@ray-core/ray": "^0.3.0-beta.6",
31
- "@ray-js/adapter": "^1.3.1-beta.7",
29
+ "@ray-core/babel-preset-remax": "^0.3.0",
30
+ "@ray-core/build-store": "^0.3.0",
31
+ "@ray-core/cli": "^0.3.0",
32
+ "@ray-core/ray": "^0.3.0",
33
+ "@ray-js/adapter": "^1.3.2",
32
34
  "@ray-js/rjs-for-wechat": "^0.0.3",
33
- "@ray-js/shared": "^1.3.1-beta.7",
34
- "@ray-js/types": "^1.3.1-beta.7",
35
+ "@ray-js/shared": "^1.3.2",
36
+ "@ray-js/types": "^1.3.2",
35
37
  "babel-loader": "^8.2.3",
36
38
  "babel-plugin-minify-dead-code-elimination": "^0.5.1",
37
39
  "babel-plugin-transform-prune-unused-imports": "^1.0.1",
@@ -48,7 +50,7 @@
48
50
  "webpack-virtual-modules": "^0.4.4"
49
51
  },
50
52
  "devDependencies": {
51
- "@ray-core/types": "^0.3.0-beta.6",
53
+ "@ray-core/types": "^0.3.0",
52
54
  "@types/jest": "^27.0.2",
53
55
  "@types/node": "^16.9.1",
54
56
  "babel-plugin-tester": "^10.1.0",
@@ -62,6 +64,6 @@
62
64
  "email": "tuyafe@tuya.com"
63
65
  }
64
66
  ],
65
- "gitHead": "3d68284d96ae18ddf2eaffa46f5d3607a51d60f8",
67
+ "gitHead": "a6af0026d8770839d9c1209a9e933b23ed77bf4a",
66
68
  "repository": {}
67
69
  }