@tarojs/helper 3.4.0-beta.3 → 3.5.0-canary.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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.injectDefineConfigHeader = void 0;
3
4
  const path = require("path");
4
5
  /**
5
6
  * Inject `defineAppConfig` and `definePageConfig`
@@ -8,8 +9,8 @@ const path = require("path");
8
9
  * if they are used
9
10
  */
10
11
  function injectDefineConfigHeader(babel) {
11
- const appConfig = 'const { defineAppConfig } = require("@tarojs/helper")';
12
- const pageConfig = 'const { definePageConfig } = require("@tarojs/helper")';
12
+ const appConfig = 'function defineAppConfig(config) { return config }';
13
+ const pageConfig = 'function definePageConfig(config) { return config }';
13
14
  const prependHeader = (nodePath, header) => {
14
15
  const parsedHeader = babel.parse(header, { filename: '' }).program.body[0];
15
16
  nodePath.node.body.unshift(parsedHeader);
@@ -35,6 +36,7 @@ function injectDefineConfigHeader(babel) {
35
36
  }
36
37
  };
37
38
  }
39
+ exports.injectDefineConfigHeader = injectDefineConfigHeader;
38
40
  function createBabelRegister({ only }) {
39
41
  require('@babel/register')({
40
42
  only: Array.from(new Set([...only])),
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ const npm = require("./npm");
11
11
  const babelRegister_1 = require("./babelRegister");
12
12
  exports.helper = Object.assign(Object.assign(Object.assign({}, constants), utils), { npm,
13
13
  createBabelRegister: babelRegister_1.default,
14
+ injectDefineConfigHeader: babelRegister_1.injectDefineConfigHeader,
14
15
  fs,
15
16
  chalk,
16
17
  chokidar,
package/dist/utils.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.readConfig = exports.definePageConfig = exports.defineAppConfig = exports.removeHeadSlash = exports.getModuleDefaultExport = exports.addPlatforms = exports.extnameExpRegOf = exports.readDirWithFileTypes = exports.getAllFilesInFloder = exports.unzip = exports.applyArrayedVisitors = exports.mergeVisitors = exports.recursiveMerge = exports.getInstalledNpmPkgVersion = exports.getInstalledNpmPkgPath = exports.pascalCase = exports.emptyDirectory = exports.cssImports = exports.generateConstantsList = exports.generateEnvList = exports.resolveScriptPath = exports.resolveMainFilePath = exports.isEmptyObject = exports.shouldUseCnpm = exports.shouldUseYarn = exports.getSystemUsername = exports.getConfig = exports.getTaroPath = exports.getUserHomeDir = exports.recursiveFindNodeModules = exports.printLog = exports.resolveStylePath = exports.promoteRelativePath = exports.replaceAliasPath = exports.isAliasPath = exports.isQuickAppPkg = exports.isNpmPkg = exports.isNodeModule = exports.normalizePath = void 0;
12
+ exports.readConfig = exports.readPageConfig = exports.removeHeadSlash = exports.getModuleDefaultExport = exports.addPlatforms = exports.extnameExpRegOf = exports.readDirWithFileTypes = exports.getAllFilesInFloder = exports.unzip = exports.applyArrayedVisitors = exports.mergeVisitors = exports.recursiveMerge = exports.getInstalledNpmPkgVersion = exports.getInstalledNpmPkgPath = exports.pascalCase = exports.emptyDirectory = exports.cssImports = exports.generateConstantsList = exports.generateEnvList = exports.resolveScriptPath = exports.resolveMainFilePath = exports.isEmptyObject = exports.shouldUseCnpm = exports.shouldUseYarn = exports.getSystemUsername = exports.getConfig = exports.getTaroPath = exports.getUserHomeDir = exports.recursiveFindNodeModules = exports.printLog = exports.resolveStylePath = exports.promoteRelativePath = exports.replaceAliasPath = exports.isAliasPath = exports.isQuickAppPkg = exports.isNpmPkg = exports.isNodeModule = exports.normalizePath = void 0;
13
13
  const fs = require("fs-extra");
14
14
  const path = require("path");
15
15
  const os = require("os");
@@ -491,14 +491,6 @@ function removeHeadSlash(str) {
491
491
  return str.replace(/^(\/|\\)/, '');
492
492
  }
493
493
  exports.removeHeadSlash = removeHeadSlash;
494
- function defineAppConfig(config) {
495
- return config;
496
- }
497
- exports.defineAppConfig = defineAppConfig;
498
- function definePageConfig(config) {
499
- return config;
500
- }
501
- exports.definePageConfig = definePageConfig;
502
494
  function analyzeImport(filePath) {
503
495
  const code = fs.readFileSync(filePath).toString();
504
496
  let importPaths = [];
@@ -600,6 +592,25 @@ function readSFCPageConfig(configPath) {
600
592
  }
601
593
  return result;
602
594
  }
595
+ function readPageConfig(configPath) {
596
+ let result = {};
597
+ const extNames = ['.js', '.jsx', '.ts', '.tsx', '.vue'];
598
+ // check source file extension
599
+ extNames.some(ext => {
600
+ const tempPath = configPath.replace('.config', ext);
601
+ if (fs.existsSync(tempPath)) {
602
+ try {
603
+ result = readSFCPageConfig(tempPath);
604
+ }
605
+ catch (error) {
606
+ result = {};
607
+ }
608
+ return true;
609
+ }
610
+ });
611
+ return result;
612
+ }
613
+ exports.readPageConfig = readPageConfig;
603
614
  function readConfig(configPath) {
604
615
  let result = {};
605
616
  if (fs.existsSync(configPath)) {
@@ -616,20 +627,7 @@ function readConfig(configPath) {
616
627
  result = exports.getModuleDefaultExport(require(configPath));
617
628
  }
618
629
  else {
619
- const extNames = ['.js', '.jsx', '.ts', '.tsx', '.vue'];
620
- // check source file extension
621
- extNames.some(ext => {
622
- const tempPath = configPath.replace('.config', ext);
623
- if (fs.existsSync(tempPath)) {
624
- try {
625
- result = readSFCPageConfig(tempPath);
626
- }
627
- catch (error) {
628
- result = {};
629
- }
630
- return true;
631
- }
632
- });
630
+ result = readPageConfig(configPath);
633
631
  }
634
632
  return result;
635
633
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/helper",
3
- "version": "3.4.0-beta.3",
3
+ "version": "3.5.0-canary.1",
4
4
  "description": "Taro Helper",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "@babel/preset-typescript": "^7.14.5",
41
41
  "@babel/register": "^7.14.5",
42
42
  "@babel/runtime": "^7.14.5",
43
- "@tarojs/taro": "3.4.0-beta.3",
43
+ "@tarojs/taro": "3.5.0-canary.1",
44
44
  "chalk": "3.0.0",
45
45
  "chokidar": "^3.3.1",
46
46
  "cross-spawn": "^7.0.3",
@@ -51,5 +51,5 @@
51
51
  "resolve": "^1.6.0",
52
52
  "yauzl": "2.10.0"
53
53
  },
54
- "gitHead": "2ef7e8c10c9e5784e98bb1ad3a803d5fd6a46c8b"
54
+ "gitHead": "c61624d2f763e6d31e67d6cf9c564efc8b0d0887"
55
55
  }
@@ -1,3 +1,6 @@
1
+ import type { PluginItem } from '@babel/core'
2
+
1
3
  export default function createBabelRegister({ only }: {
2
4
  only: any;
3
5
  }): void;
6
+ export function injectDefineConfigHeader (babel: any): PluginItem;
package/types/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import chalk from 'chalk';
5
5
  import { processTypeEnum, IProcessTypeMap } from './constants';
6
6
  import * as utils from './utils';
7
7
  import * as npm from './npm';
8
- import createBabelRegister from './babelRegister';
8
+ import createBabelRegister, { injectDefineConfigHeader } from './babelRegister';
9
9
 
10
10
  export declare enum META_TYPE {
11
11
  ENTRY = 'ENTRY',
@@ -27,6 +27,7 @@ export declare enum FRAMEWORK_MAP {
27
27
  declare interface helper {
28
28
  npm: typeof npm;
29
29
  createBabelRegister: typeof createBabelRegister;
30
+ injectDefineConfigHeader: typeof injectDefineConfigHeader;
30
31
  fs: typeof fs;
31
32
  chokidar: typeof chokidar;
32
33
  chalk: typeof chalk;
@@ -74,6 +75,7 @@ declare interface helper {
74
75
  getModuleDefaultExport: (exports: any) => any;
75
76
  removeHeadSlash: (str: string) => string;
76
77
  readConfig: (configPath: string) => any;
78
+ readPageConfig: (configPath: string) => any;
77
79
  PLATFORMS: any;
78
80
  processTypeEnum: typeof processTypeEnum;
79
81
  processTypeMap: IProcessTypeMap;
package/types/utils.d.ts CHANGED
@@ -43,3 +43,4 @@ export declare function addPlatforms(platform: string): void;
43
43
  export declare const getModuleDefaultExport: (exports: any) => any;
44
44
  export declare const removeHeadSlash: (str: string) => string;
45
45
  export declare const readConfig: (configPath: string) => any;
46
+ export declare const readPageConfig: (configPath: string) => any;