@ray-js/builder-mp 0.10.2 → 0.20.0-beta.1

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.
@@ -152,13 +152,24 @@ function ContextAndHoc() {
152
152
  let exportDefaultDeclarationName;
153
153
  return {
154
154
  pre(state) {
155
+ isPage = false;
155
156
  exportDefaultDeclarationName = '';
156
157
  entries = Object.keys(builder_1.builder.entry);
157
158
  const sourceDir = (0, slash_1.default)(P.join(builder_1.builder.options.cwd, builder_1.builder.options.source));
158
159
  const filename = (0, slash_1.default)(state.opts.filename);
159
160
  const fileName = P.relative(sourceDir, filename);
160
- const fileEntryName = fileName.replace(P.extname(fileName), '');
161
- isPage = fileEntryName.toLowerCase() !== 'app' && entries.some((e) => e === fileEntryName);
161
+ const ext = P.extname(fileName);
162
+ const entryNames = ['.mini', `.${builder_1.builder.options.target}`, ''].map((x) => fileName.replace(`${x}${ext}`, ''));
163
+ for (const p of entryNames) {
164
+ if (p.toLowerCase() === 'app')
165
+ return;
166
+ for (const e of entries) {
167
+ if (e === p) {
168
+ isPage = true;
169
+ return;
170
+ }
171
+ }
172
+ }
162
173
  },
163
174
  visitor: {
164
175
  ExportDefaultDeclaration(path, state) {
package/lib/build.js CHANGED
@@ -17,7 +17,7 @@ const shared_1 = require("@ray-js/shared");
17
17
  const legacyExport_1 = require("@ray-core/cli/lib/legacyExport");
18
18
  const package_json_1 = __importDefault(require("@ray-core/cli/package.json"));
19
19
  const builder_1 = require("./builder");
20
- const build_rjs_1 = __importDefault(require("./build.rjs"));
20
+ const builder_rjs_1 = __importDefault(require("./builder.rjs"));
21
21
  const ray_core_1 = require("./ray-core");
22
22
  colors_1.default.enable();
23
23
  const LOG_PREFIX = 'builder-mp';
@@ -36,15 +36,15 @@ const defaultCompileOptions = {
36
36
  function build(options, context) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  const { api } = context;
39
- let compileOptions = Object.assign({}, defaultCompileOptions, options);
40
- const { cwd, target, output, devtools } = compileOptions;
39
+ let compileOptions = Object.assign({}, defaultCompileOptions, api.config, options);
40
+ const { cwd, target, output, devtools, onTargetDir } = compileOptions;
41
41
  /**
42
42
  * 又是历史原因
43
43
  * 因老项目生成的产物目录是tuya,所以就干脆是tuya,不然会出现既 tuya 又 thing 的目录
44
44
  * 将开发整懵逼
45
45
  */
46
46
  const dist = target === 'thing' ? 'tuya' : target;
47
- const outputPath = (0, shared_1.resolvePath)([output, dist], { cwd });
47
+ const outputPath = (0, shared_1.resolvePath)(typeof onTargetDir === 'function' ? [onTargetDir(output, dist)] : [output, dist], { cwd });
48
48
  // 上下文共享 options
49
49
  builder_1.builder.api = api;
50
50
  builder_1.builder.options = compileOptions = Object.assign({}, compileOptions, { output: outputPath });
@@ -55,11 +55,11 @@ function build(options, context) {
55
55
  if (devtools) {
56
56
  shared_1.log.info(LOG_PREFIX, '开启 devtools 开发者工具环境变量'.yellow, devtools);
57
57
  }
58
- const rayCoreOpts = (0, ray_core_1.getRayCoreOptions)(build_rjs_1.default);
58
+ const rayCoreOpts = (0, ray_core_1.getRayCoreOptions)();
59
59
  const rayApi = new ray_core_1.RayAPI(rayCoreOpts);
60
60
  // 编译除rjs模块外的小程序模块
61
61
  const compiler = (0, legacyExport_1.buildMini)(rayApi, rayCoreOpts);
62
- build_rjs_1.default.init(compiler, compileOptions); // TODO rjs 可用动态虚拟模块实现单webpack编译
62
+ builder_rjs_1.default.init(compiler, compileOptions); // TODO rjs 可用动态虚拟模块实现单webpack编译
63
63
  return compiler;
64
64
  });
65
65
  }
@@ -105,6 +105,7 @@ class RjsBuilder {
105
105
  .end() // rjs模块需要导出给minipack 使用,蹩脚
106
106
  .optimization.runtimeChunk({ name: 'runtime-rjs' })
107
107
  .splitChunks({ cacheGroups });
108
+ cfg.output.delete('libraryExport');
108
109
  cfg.output.set('clean', false);
109
110
  const config = cfg.toConfig();
110
111
  config.entry = () => this.entries;
@@ -1,5 +1,29 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const babel = __importStar(require("@babel/core"));
3
27
  // TODO 动态生成app.config.ts文件还是会造成二次编译,待优化
4
28
  // 原有实现方案会造成二次编译,导致编译性能下降
5
29
  // https://registry.code.tuya-inc.top/godzilla/ray-monorepo/-/blob/3bb0c0754881b4bc0ebdb4540f628c941bfb3be8/packages/builder-mp/src/webpack/plugins/AppFrameworkEntry/index.ts
@@ -13,11 +37,44 @@ function configWebpack(context) {
13
37
  if (thePlugin._staticModules) {
14
38
  const file = Object.keys(thePlugin._staticModules).find((name) => /\/?app\./.test(name));
15
39
  const source = thePlugin._staticModules[file];
16
- const content = `import '@ray-js/ray/main';${source}`;
40
+ const content = `
41
+ import router from '@ray-js/ray/main';
42
+ ${updateCode(source, file)};
43
+ function reOverloadNativeAppConstructor(config) {
44
+ const app = overloadNativeAppConstructor(config);
45
+ return function(opts) {
46
+ const cfg = app(opts);
47
+ cfg.asSubPackageRuntimeOptions && router.setUrlPrefix(cfg.asSubPackageRuntimeOptions.subPackageRoot);
48
+ return cfg;
49
+ }
50
+ }
51
+ `;
17
52
  thePlugin._staticModules[file] = content;
18
53
  plugin.set('plugin', thePlugin);
19
54
  }
20
55
  }
56
+ function updateCode(code, name) {
57
+ const opts = {
58
+ plugins: [
59
+ function () {
60
+ return {
61
+ visitor: {
62
+ Identifier(path) {
63
+ if (path.parent.type === 'CallExpression' &&
64
+ path.node.name === 'overloadNativeAppConstructor') {
65
+ path.node.name = 'reOverloadNativeAppConstructor';
66
+ }
67
+ },
68
+ },
69
+ };
70
+ },
71
+ ],
72
+ sourceFileName: name,
73
+ filename: name,
74
+ };
75
+ const res = babel.transformSync(code, opts);
76
+ return res === null || res === void 0 ? void 0 : res.code;
77
+ }
21
78
  exports.default = {
22
79
  name: 'app-entry-wrapper',
23
80
  configWebpack,
@@ -26,7 +26,7 @@ exports.default = {
26
26
  configWebpack(context) {
27
27
  const { config } = context;
28
28
  const { target } = builder_1.builder.options;
29
- // alias('ray', '@ray-js/ray', config)
29
+ alias('ray', '@ray-js/ray', config);
30
30
  // 修改 mini-css-extract-plugin 的配置
31
31
  config.plugin('mini-css-extract-plugin').tap(([options]) => [Object.assign(Object.assign({}, options), { ignoreOrder: true })]);
32
32
  // 收敛 babel.config 配置
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ configWebpack({ config }: {
3
+ config: any;
4
+ }): void;
5
+ };
6
+ export default _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const builder_rjs_1 = __importDefault(require("../builder.rjs"));
7
+ exports.default = {
8
+ configWebpack({ config }) {
9
+ builder_rjs_1.default.config(config);
10
+ },
11
+ };
package/lib/ray-core.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { Options, Platform } from '@ray-core/types';
2
2
  import RayCoreAPI from '@ray-core/cli/lib/API';
3
- import type { RjsBuilder } from './build.rjs';
4
- export declare function getRayCoreOptions(rjsBuilder: RjsBuilder): Options;
3
+ export declare function getRayCoreOptions(): Options;
5
4
  export declare class RayAPI extends RayCoreAPI {
6
5
  constructor(opts: Options);
7
6
  registerAdapterPlugins(target: Platform): void;
package/lib/ray-core.js CHANGED
@@ -19,39 +19,43 @@ const path_1 = __importDefault(require("path"));
19
19
  const legacyExport_1 = require("@ray-core/cli/lib/legacyExport");
20
20
  const API_1 = __importDefault(require("@ray-core/cli/lib/API"));
21
21
  const build_store_1 = __importDefault(require("@ray-core/build-store"));
22
+ const BlendedApp_1 = __importDefault(require("@ray-core/cli/lib/plugins/BlendedApp"));
22
23
  const resolve_alias_1 = __importDefault(require("./plugins/resolve-alias"));
23
24
  const app_entry_1 = __importDefault(require("./plugins/app-entry"));
24
25
  const less_1 = __importDefault(require("./plugins/less"));
25
26
  const resolve_legacy_1 = __importDefault(require("./plugins/resolve-legacy"));
27
+ const rjs_1 = __importDefault(require("./plugins/rjs"));
26
28
  const builder_1 = require("./builder");
27
29
  const _a = (0, legacyExport_1.getDefaultOptions)(), { UNSAFE_wechatTemplateDepth } = _a, remaxDefaultOptions = __rest(_a, ["UNSAFE_wechatTemplateDepth"]);
28
- const defaultTemplateDepth = {
29
- swiper: 3,
30
- text: 1,
31
- ad: -1,
32
- 'match-media': -1,
33
- 'page-container': -1,
34
- 'share-element': -1,
35
- 'keyboard-accessory': -1,
36
- 'voip-room': -1,
37
- 'ad-custom': -1,
38
- 'page-meta': -1,
39
- 'navigation-bar': -1,
40
- };
41
- const innerPlugins = [resolve_legacy_1.default, app_entry_1.default, less_1.default, resolve_alias_1.default];
42
- function getRayCoreOptions(rjsBuilder) {
43
- const { cwd, source, watch, target, mini, analyze, output } = builder_1.builder.options;
30
+ const isThing = process.env.PLATFORM === 'thing';
31
+ const defaultTemplateDepth = isThing
32
+ ? {
33
+ swiper: 3,
34
+ text: 1,
35
+ ad: -1,
36
+ 'match-media': -1,
37
+ 'page-container': -1,
38
+ 'share-element': -1,
39
+ 'keyboard-accessory': -1,
40
+ 'voip-room': -1,
41
+ 'ad-custom': -1,
42
+ 'page-meta': -1,
43
+ 'navigation-bar': -1,
44
+ }
45
+ : {};
46
+ const innerPlugins = [resolve_legacy_1.default, app_entry_1.default, less_1.default, resolve_alias_1.default, rjs_1.default];
47
+ function getRayCoreOptions() {
48
+ const { cwd, source, watch, target, mini, analyze, output, blended } = builder_1.builder.options;
49
+ if (blended) {
50
+ innerPlugins.push(BlendedApp_1.default);
51
+ }
44
52
  const api = builder_1.builder.api;
45
- const injectWebpackConfigToRjs = {
46
- configWebpack({ config }) {
47
- rjsBuilder.config(config);
48
- },
49
- };
50
53
  // @ts-ignore
51
- const plugins = innerPlugins.concat(api.plugins, injectWebpackConfigToRjs);
54
+ const plugins = innerPlugins.concat(api.plugins);
52
55
  const remaxBuildConfig = Object.assign(Object.assign({}, remaxDefaultOptions), { UNSAFE_wechatTemplateDepth: Object.assign(UNSAFE_wechatTemplateDepth, defaultTemplateDepth), compressTemplate: mini, pxToRpx: false, minimize: mini, analyze,
53
56
  cwd, loglevel: 'warn', rootDir: source, target, output: path_1.default.relative(cwd, output), watch,
54
- plugins });
57
+ plugins,
58
+ blended });
55
59
  return remaxBuildConfig;
56
60
  }
57
61
  exports.getRayCoreOptions = getRayCoreOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/builder-mp",
3
- "version": "0.10.2",
3
+ "version": "0.20.0-beta.1",
4
4
  "description": "Ray builder for mini program",
5
5
  "keywords": [
6
6
  "ray"
@@ -24,14 +24,14 @@
24
24
  "@babel/template": "^7.16.0",
25
25
  "@babel/traverse": "^7.16.3",
26
26
  "@babel/types": "^7.16.0",
27
- "@ray-core/babel-preset-remax": "^0.1.3",
28
- "@ray-core/build-store": "^0.1.3",
29
- "@ray-core/cli": "^0.1.3",
30
- "@ray-core/ray": "^0.1.3",
31
- "@ray-js/adapter": "^0.10.2",
27
+ "@ray-core/babel-preset-remax": "^0.2.0-beta.6",
28
+ "@ray-core/build-store": "^0.2.0-beta.6",
29
+ "@ray-core/cli": "^0.2.0-beta.6",
30
+ "@ray-core/ray": "^0.2.0-beta.6",
31
+ "@ray-js/adapter": "^0.20.0-beta.1",
32
32
  "@ray-js/rjs-for-wechat": "^0.0.3",
33
- "@ray-js/shared": "^0.10.2",
34
- "@ray-js/types": "^0.10.2",
33
+ "@ray-js/shared": "^0.20.0-beta.1",
34
+ "@ray-js/types": "^0.20.0-beta.1",
35
35
  "babel-loader": "^8.2.3",
36
36
  "babel-plugin-minify-dead-code-elimination": "^0.5.1",
37
37
  "babel-plugin-transform-prune-unused-imports": "^1.0.1",
@@ -48,7 +48,7 @@
48
48
  "webpack-virtual-modules": "^0.4.4"
49
49
  },
50
50
  "devDependencies": {
51
- "@ray-core/types": "^0.1.3",
51
+ "@ray-core/types": "^0.2.0-beta.6",
52
52
  "@types/jest": "^27.0.2",
53
53
  "@types/node": "^16.9.1",
54
54
  "babel-plugin-tester": "^10.1.0",
@@ -62,6 +62,6 @@
62
62
  "email": "tuyafe@tuya.com"
63
63
  }
64
64
  ],
65
- "gitHead": "05f65fee00b3174d78bd9201df6eb8cedfcfe03f",
65
+ "gitHead": "bbd6144c9594e4f18317127a74f4e5129aae1e6b",
66
66
  "repository": {}
67
67
  }
File without changes