@modern-js/module-tools 1.1.3 → 1.1.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 2da27d3b: fix sourcemap 'source' config
8
+ - Updated dependencies [5e3de7d8]
9
+ - Updated dependencies [2da27d3b]
10
+ - Updated dependencies [4819a3c7]
11
+ - Updated dependencies [b7fb82ec]
12
+ - Updated dependencies [81d93503]
13
+ - @modern-js/plugin-i18n@1.1.2
14
+ - @modern-js/babel-compiler@1.1.4
15
+ - @modern-js/new-action@1.2.2
16
+ - @modern-js/plugin-changeset@1.1.2
17
+ - @modern-js/utils@1.1.6
18
+
19
+ ## 1.1.4
20
+
21
+ ### Patch Changes
22
+
23
+ - 10676d31: fix build watch error
24
+
3
25
  ## 1.1.3
4
26
 
5
27
  ### Patch Changes
@@ -5,6 +5,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
7
  import { Import, fs } from '@modern-js/utils';
8
+ import { initEnv } from "../utils/init-env";
8
9
  const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
9
10
  const glob = Import.lazy('glob', require);
10
11
  const argv = Import.lazy('process.argv', require);
@@ -62,7 +63,8 @@ export const getWillCompilerCode = (srcDirOrFile, option) => {
62
63
  const exts = getExts(isTsProject);
63
64
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
64
65
  const files = glob.sync(globPattern, {
65
- ignore: [`${srcDirOrFile}/**/*.d.ts`]
66
+ ignore: [`${srcDirOrFile}/**/*.d.ts`],
67
+ absolute: true
66
68
  });
67
69
  return files;
68
70
  };
@@ -113,20 +115,6 @@ const generatorRealFiles = virtualDists => {
113
115
  }
114
116
  };
115
117
 
116
- export const initEnv = ({
117
- syntax,
118
- type
119
- }) => {
120
- if (syntax === 'es6+' && type === 'commonjs') {
121
- return 'CJS_ES6';
122
- } else if (syntax === 'es6+' && type === 'module') {
123
- return 'ESM_ES6';
124
- } else if (syntax === 'es5' && type === 'module') {
125
- return 'ESM_ES5';
126
- }
127
-
128
- return '';
129
- };
130
118
  const defaultConfig = {
131
119
  srcRootDir: `${process.cwd()}/src`,
132
120
  willCompilerDirOrFile: `${process.cwd()}/src`,
@@ -1,5 +1,11 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
1
7
  import { Import, fs } from '@modern-js/utils';
2
- import { initEnv } from "./build-source-code";
8
+ import { initEnv } from "../utils/init-env";
3
9
  const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
4
10
  const logger = Import.lazy('../features/build/logger', require);
5
11
  const ts = Import.lazy('../utils/tsconfig', require);
@@ -61,7 +67,9 @@ const runBabelCompiler = async (config, modernConfig) => {
61
67
  distDir: config.distDir,
62
68
  watchDir: config.srcRootDir,
63
69
  extensions: getExts(isTs)
64
- }, babelConfig);
70
+ }, _objectSpread(_objectSpread({}, babelConfig), {}, {
71
+ sourceMaps: config.sourceMaps
72
+ }));
65
73
  emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
66
74
  console.info(logger.clearFlag, `Compiling...`);
67
75
  });
@@ -0,0 +1,14 @@
1
+ export const initEnv = ({
2
+ syntax,
3
+ type
4
+ }) => {
5
+ if (syntax === 'es6+' && type === 'commonjs') {
6
+ return 'CJS_ES6';
7
+ } else if (syntax === 'es6+' && type === 'module') {
8
+ return 'ESM_ES6';
9
+ } else if (syntax === 'es5' && type === 'module') {
10
+ return 'ESM_ES5';
11
+ }
12
+
13
+ return '';
14
+ };
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.initEnv = exports.getWillCompilerCode = exports.buildSourceCode = exports.Compiler = void 0;
6
+ exports.getWillCompilerCode = exports.buildSourceCode = exports.Compiler = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
10
+ var _initEnv = require("../utils/init-env");
11
+
10
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
13
 
12
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -77,7 +79,8 @@ const getWillCompilerCode = (srcDirOrFile, option) => {
77
79
  const exts = getExts(isTsProject);
78
80
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
79
81
  const files = glob.sync(globPattern, {
80
- ignore: [`${srcDirOrFile}/**/*.d.ts`]
82
+ ignore: [`${srcDirOrFile}/**/*.d.ts`],
83
+ absolute: true
81
84
  });
82
85
  return files;
83
86
  };
@@ -136,22 +139,6 @@ const generatorRealFiles = virtualDists => {
136
139
  }
137
140
  };
138
141
 
139
- const initEnv = ({
140
- syntax,
141
- type
142
- }) => {
143
- if (syntax === 'es6+' && type === 'commonjs') {
144
- return 'CJS_ES6';
145
- } else if (syntax === 'es6+' && type === 'module') {
146
- return 'ESM_ES6';
147
- } else if (syntax === 'es5' && type === 'module') {
148
- return 'ESM_ES5';
149
- }
150
-
151
- return '';
152
- };
153
-
154
- exports.initEnv = initEnv;
155
142
  const defaultConfig = {
156
143
  srcRootDir: `${process.cwd()}/src`,
157
144
  willCompilerDirOrFile: `${process.cwd()}/src`,
@@ -171,7 +158,7 @@ const taskMain = async ({
171
158
  // Execution of the script's parameter handling and related required configuration acquisition
172
159
  const processArgv = argv(process.argv.slice(2));
173
160
  const config = processArgv(defaultConfig);
174
- process.env.BUILD_FORMAT = initEnv(config);
161
+ process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
175
162
  const compiler = Compiler.babel; // Currently, only babel is supported.
176
163
 
177
164
  const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
@@ -2,7 +2,13 @@
2
2
 
3
3
  var _utils = require("@modern-js/utils");
4
4
 
5
- var _buildSourceCode = require("./build-source-code");
5
+ var _initEnv = require("../utils/init-env");
6
+
7
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
+
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
12
 
7
13
  const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
8
14
 
@@ -73,7 +79,9 @@ const runBabelCompiler = async (config, modernConfig) => {
73
79
  distDir: config.distDir,
74
80
  watchDir: config.srcRootDir,
75
81
  extensions: getExts(isTs)
76
- }, babelConfig);
82
+ }, _objectSpread(_objectSpread({}, babelConfig), {}, {
83
+ sourceMaps: config.sourceMaps
84
+ }));
77
85
  emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
78
86
  console.info(logger.clearFlag, `Compiling...`);
79
87
  });
@@ -136,7 +144,7 @@ const taskMain = async ({
136
144
  syntax: 'es5',
137
145
  type: 'module'
138
146
  });
139
- process.env.BUILD_FORMAT = (0, _buildSourceCode.initEnv)(config);
147
+ process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
140
148
  await buildSourceCode(config, modernConfig);
141
149
  };
142
150
 
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initEnv = void 0;
7
+
8
+ const initEnv = ({
9
+ syntax,
10
+ type
11
+ }) => {
12
+ if (syntax === 'es6+' && type === 'commonjs') {
13
+ return 'CJS_ES6';
14
+ } else if (syntax === 'es6+' && type === 'module') {
15
+ return 'ESM_ES6';
16
+ } else if (syntax === 'es5' && type === 'module') {
17
+ return 'ESM_ES5';
18
+ }
19
+
20
+ return '';
21
+ };
22
+
23
+ exports.initEnv = initEnv;
@@ -22,24 +22,4 @@ export declare const getWillCompilerCode: (srcDirOrFile: string, option: {
22
22
  isTsProject: boolean;
23
23
  }) => string[];
24
24
  export declare const buildSourceCode: (config: IBuildSourceCodeConfig) => Promise<import("@modern-js/babel-compiler").ICompilerResult>;
25
- export declare const initEnv: ({
26
- syntax,
27
- type
28
- }: {
29
- syntax: ITaskConfig['syntax'];
30
- type: ITaskConfig['type'];
31
- }) => "" | "CJS_ES6" | "ESM_ES6" | "ESM_ES5";
32
- interface ITaskConfig {
33
- srcRootDir: string;
34
- willCompilerDirOrFile: string;
35
- distDir: string;
36
- appDirectory: string;
37
- sourceMaps: boolean;
38
- syntax: 'es5' | 'es6+';
39
- type: 'module' | 'commonjs';
40
- tsconfigPath: string;
41
- copyDirs?: string;
42
- compiler?: 'babel' | 'esbuild' | 'swc';
43
- watch: boolean;
44
- }
45
25
  export {};
@@ -0,0 +1,21 @@
1
+ interface ITaskConfig {
2
+ srcRootDir: string;
3
+ willCompilerDirOrFile: string;
4
+ distDir: string;
5
+ appDirectory: string;
6
+ sourceMaps: boolean;
7
+ syntax: 'es5' | 'es6+';
8
+ type: 'module' | 'commonjs';
9
+ tsconfigPath: string;
10
+ copyDirs?: string;
11
+ compiler?: 'babel' | 'esbuild' | 'swc';
12
+ watch: boolean;
13
+ }
14
+ export declare const initEnv: ({
15
+ syntax,
16
+ type
17
+ }: {
18
+ syntax: ITaskConfig['syntax'];
19
+ type: ITaskConfig['type'];
20
+ }) => "" | "CJS_ES6" | "ESM_ES6" | "ESM_ES5";
21
+ export {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.3",
14
+ "version": "1.1.5",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js"
17
17
  },
@@ -44,19 +44,19 @@
44
44
  "@babel/runtime": "^7",
45
45
  "@babel/traverse": "^7.15.0",
46
46
  "@babel/types": "^7.15.0",
47
- "@modern-js/babel-compiler": "^1.1.3",
47
+ "@modern-js/babel-compiler": "^1.1.4",
48
48
  "@modern-js/babel-preset-module": "^1.1.2",
49
49
  "@modern-js/core": "^1.2.0",
50
50
  "@modern-js/css-config": "^1.1.2",
51
51
  "@modern-js/i18n-cli-language-detector": "^1.1.1",
52
52
  "@modern-js/module-tools-hooks": "^1.1.2",
53
- "@modern-js/new-action": "^1.2.0",
53
+ "@modern-js/new-action": "^1.2.1",
54
54
  "@modern-js/plugin-analyze": "^1.1.2",
55
- "@modern-js/plugin-changeset": "^1.1.1",
55
+ "@modern-js/plugin-changeset": "^1.1.2",
56
56
  "@modern-js/plugin-fast-refresh": "^1.1.1",
57
- "@modern-js/plugin-i18n": "^1.1.1",
57
+ "@modern-js/plugin-i18n": "^1.1.2",
58
58
  "@modern-js/style-compiler": "^1.1.3",
59
- "@modern-js/utils": "^1.1.5",
59
+ "@modern-js/utils": "^1.1.6",
60
60
  "chalk": "^4.1.2",
61
61
  "chokidar": "^3.5.2",
62
62
  "dotenv": "^10.0.0",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@babel/preset-typescript": "^7.15.0",
78
- "@modern-js/babel-chain": "^1.1.1",
78
+ "@modern-js/babel-chain": "^1.1.2",
79
79
  "@types/babel__core": "^7.1.15",
80
80
  "@types/babel__generator": "^7.6.3",
81
81
  "@types/babel__traverse": "^7.14.2",
@@ -88,8 +88,8 @@
88
88
  "@types/signale": "^1.4.2",
89
89
  "commander": "^8.1.0",
90
90
  "typescript": "^4",
91
- "@modern-js/plugin-testing": "^1.1.1",
92
- "@modern-js/module-tools": "^1.1.2"
91
+ "@modern-js/plugin-testing": "^1.2.2",
92
+ "@modern-js/module-tools": "^1.1.4"
93
93
  },
94
94
  "sideEffects": false,
95
95
  "modernConfig": {
@@ -2,6 +2,7 @@ import { Import, fs } from '@modern-js/utils';
2
2
  import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
3
3
  import type { BabelOptions, IVirtualDist } from '@modern-js/babel-compiler';
4
4
  import type { ITsconfig } from '../types';
5
+ import { initEnv } from '../utils/init-env';
5
6
 
6
7
  const babelCompiler: typeof import('@modern-js/babel-compiler') = Import.lazy(
7
8
  '@modern-js/babel-compiler',
@@ -91,6 +92,7 @@ export const getWillCompilerCode = (
91
92
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
92
93
  const files = glob.sync(globPattern, {
93
94
  ignore: [`${srcDirOrFile}/**/*.d.ts`],
95
+ absolute: true,
94
96
  });
95
97
 
96
98
  return files;
@@ -138,24 +140,6 @@ const generatorRealFiles = (virtualDists: IVirtualDist[]) => {
138
140
  }
139
141
  };
140
142
 
141
- export const initEnv = ({
142
- syntax,
143
- type,
144
- }: {
145
- syntax: ITaskConfig['syntax'];
146
- type: ITaskConfig['type'];
147
- }) => {
148
- if (syntax === 'es6+' && type === 'commonjs') {
149
- return 'CJS_ES6';
150
- } else if (syntax === 'es6+' && type === 'module') {
151
- return 'ESM_ES6';
152
- } else if (syntax === 'es5' && type === 'module') {
153
- return 'ESM_ES5';
154
- }
155
-
156
- return '';
157
- };
158
-
159
143
  interface ITaskConfig {
160
144
  srcRootDir: string; // 源码的根目录
161
145
  willCompilerDirOrFile: string; // 用于编译的源码文件或者源码目录
@@ -2,7 +2,7 @@ import { Import, fs } from '@modern-js/utils';
2
2
  import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
3
3
  import type { ICompilerResult, IVirtualDist } from '@modern-js/babel-compiler';
4
4
  import type { ITsconfig } from '../types';
5
- import { initEnv } from './build-source-code';
5
+ import { initEnv } from '../utils/init-env';
6
6
 
7
7
  const babelCompiler: typeof import('@modern-js/babel-compiler') = Import.lazy(
8
8
  '@modern-js/babel-compiler',
@@ -82,7 +82,7 @@ const runBabelCompiler = async (
82
82
  watchDir: config.srcRootDir,
83
83
  extensions: getExts(isTs),
84
84
  },
85
- babelConfig,
85
+ { ...babelConfig, sourceMaps: config.sourceMaps },
86
86
  );
87
87
  emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
88
88
  console.info(logger.clearFlag, `Compiling...`);
@@ -0,0 +1,31 @@
1
+ interface ITaskConfig {
2
+ srcRootDir: string; // 源码的根目录
3
+ willCompilerDirOrFile: string; // 用于编译的源码文件或者源码目录
4
+ distDir: string;
5
+ appDirectory: string;
6
+ sourceMaps: boolean;
7
+ syntax: 'es5' | 'es6+';
8
+ type: 'module' | 'commonjs';
9
+ tsconfigPath: string;
10
+ copyDirs?: string;
11
+ compiler?: 'babel' | 'esbuild' | 'swc';
12
+ watch: boolean;
13
+ }
14
+
15
+ export const initEnv = ({
16
+ syntax,
17
+ type,
18
+ }: {
19
+ syntax: ITaskConfig['syntax'];
20
+ type: ITaskConfig['type'];
21
+ }) => {
22
+ if (syntax === 'es6+' && type === 'commonjs') {
23
+ return 'CJS_ES6';
24
+ } else if (syntax === 'es6+' && type === 'module') {
25
+ return 'ESM_ES6';
26
+ } else if (syntax === 'es5' && type === 'module') {
27
+ return 'ESM_ES5';
28
+ }
29
+
30
+ return '';
31
+ };