@ray-js/build-plugin-router 1.3.1 → 1.3.3

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 (2) hide show
  1. package/lib/index.js +19 -12
  2. package/package.json +4 -4
package/lib/index.js CHANGED
@@ -169,6 +169,7 @@ function PluginRouter(api) {
169
169
  let cacheThemeLocation = {};
170
170
  let timerId;
171
171
  let themeLocation;
172
+ const { source } = api.options;
172
173
  const plugin = {
173
174
  name: '@ray-js/build-plugin-router',
174
175
  setup() {
@@ -177,10 +178,10 @@ function PluginRouter(api) {
177
178
  if (api.options.watch) {
178
179
  chokidar_1.default
179
180
  .watch(['**/*.config.ts', '**/*.config.js', '!app.config.{js,ts}'], {
180
- cwd: path_1.default.join(api.options.cwd, api.options.source),
181
+ cwd: path_1.default.join(api.options.cwd, source),
181
182
  })
182
183
  .on('change', (file) => {
183
- const filePath = path_1.default.join(api.options.cwd, api.options.source, file);
184
+ const filePath = path_1.default.join(api.options.cwd, source, file);
184
185
  // 配置文件引用存在 cache
185
186
  delete require.cache[require.resolve(filePath)];
186
187
  // FIXME: 引用文件变更也需要重新构建
@@ -189,11 +190,11 @@ function PluginRouter(api) {
189
190
  }
190
191
  },
191
192
  readConfigFromConfigFile() {
192
- const routesConfigFile = api.searchJSFile('src/routes.config');
193
+ const routesConfigFile = api.searchJSFile(`${source}/routes.config`);
193
194
  if (!routesConfigFile) {
194
195
  throw new Error(`missing configuration file (routes.config.{ts|js})`);
195
196
  }
196
- const globalConfigFile = api.searchJSFile('src/global.config');
197
+ const globalConfigFile = api.searchJSFile(`${source}/global.config`);
197
198
  const routesConfig = api.requireJSFile(routesConfigFile);
198
199
  const globalConfig = globalConfigFile ? api.requireJSFile(globalConfigFile, '*') : {};
199
200
  return { routesConfig, globalConfig };
@@ -245,13 +246,19 @@ function PluginRouter(api) {
245
246
  const subPkgs = (_d = subPackages !== null && subPackages !== void 0 ? subPackages : subpackages) !== null && _d !== void 0 ? _d : [];
246
247
  const pages = lodash_1.default.uniq(_routes.map((r) => r.path.replace(/^\//, '')));
247
248
  const tabBar = normalizeTabBarConfig(_tabBar, _routes, standardAppConfigFieldMap);
248
- let workers = otherConfig.workers;
249
- if (workers && typeof workers !== 'string') {
250
- workers = workers.root;
251
- }
249
+ const { workers = [], root: workerRoot } = otherConfig.workers || {};
252
250
  const config = Object.assign(Object.assign(Object.assign({}, g), otherConfig), { pages, tabBar });
253
- if (workers) {
254
- config.workers = workers;
251
+ if (workerRoot) {
252
+ config.workers =
253
+ target !== 'thing'
254
+ ? workerRoot
255
+ : workers.map((w) => {
256
+ const ext = path_1.default.extname(w);
257
+ if (ext) {
258
+ w = w.replace(new RegExp(`${ext}$`), '');
259
+ }
260
+ return `${workerRoot}/${w}.js`;
261
+ });
255
262
  }
256
263
  if (subPkgs && subPkgs.length) {
257
264
  config.subpackages = subPkgs.map((pkg) => {
@@ -275,8 +282,8 @@ function PluginRouter(api) {
275
282
  }
276
283
  const templateFile = path_1.default.join(__dirname, '../templates/app.config.ejs');
277
284
  const context = ejsRender(templateFile, { appConfig: { [target]: data } });
278
- api.writeFile('src/app.config.ts', context);
279
- shared_1.log.verbose(LOG_PREFIX, `generate`, 'src/app.config.ts'.underline.green, `for wechat platform`);
285
+ api.writeFile(`${source}/app.config.ts`, context);
286
+ shared_1.log.verbose(LOG_PREFIX, `generate`, `${source}/app.config.ts`.underline.green, `for wechat platform`);
280
287
  },
281
288
  };
282
289
  // todo theme 逻辑不应该在这个文件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/build-plugin-router",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Ray build plugin for router",
5
5
  "keywords": [
6
6
  "ray"
@@ -21,7 +21,7 @@
21
21
  "watch": "tsc -p ./tsconfig.build.json --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@ray-js/shared": "^1.3.1",
24
+ "@ray-js/shared": "^1.3.3",
25
25
  "chokidar": "^3.5.2",
26
26
  "colors": "1.4.0",
27
27
  "ejs": "^3.1.6",
@@ -30,7 +30,7 @@
30
30
  "url": "^0.11.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@ray-js/types": "^1.3.1"
33
+ "@ray-js/types": "^1.3.3"
34
34
  },
35
35
  "maintainers": [
36
36
  {
@@ -38,6 +38,6 @@
38
38
  "email": "tuyafe@tuya.com"
39
39
  }
40
40
  ],
41
- "gitHead": "4844c0f03bb434999b2e93196dba1cd53b9b6c56",
41
+ "gitHead": "78ca2269ac5efb52e102029258aab74c0a700c68",
42
42
  "repository": {}
43
43
  }