@modern-js/server-utils 2.5.1-alpha.0 → 2.7.0

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 (33) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/cjs/common/index.js +4 -0
  3. package/dist/cjs/compilers/babel/index.js +4 -0
  4. package/dist/cjs/compilers/typescript/index.js +8 -4
  5. package/dist/cjs/compilers/typescript/{tsconfig-paths-plugin.js → tsconfigPathsPlugin.js} +7 -3
  6. package/dist/cjs/compilers/typescript/{typescript-loader.js → typescriptLoader.js} +3 -3
  7. package/dist/esm/compilers/typescript/index.js +2 -2
  8. package/dist/esm-node/compilers/typescript/index.js +2 -2
  9. package/package.json +9 -9
  10. package/dist/js/modern/common/index.js +0 -55
  11. package/dist/js/modern/compilers/babel/index.js +0 -149
  12. package/dist/js/modern/compilers/typescript/index.js +0 -123
  13. package/dist/js/modern/compilers/typescript/tsconfig-paths-plugin.js +0 -187
  14. package/dist/js/modern/compilers/typescript/typescript-loader.js +0 -24
  15. package/dist/js/modern/index.js +0 -5
  16. package/dist/js/node/common/index.js +0 -85
  17. package/dist/js/node/compilers/babel/index.js +0 -178
  18. package/dist/js/node/compilers/typescript/index.js +0 -150
  19. package/dist/js/node/compilers/typescript/tsconfig-paths-plugin.js +0 -216
  20. package/dist/js/node/compilers/typescript/typescript-loader.js +0 -47
  21. package/dist/js/node/index.js +0 -29
  22. package/dist/js/treeshaking/common/index.js +0 -204
  23. package/dist/js/treeshaking/compilers/babel/index.js +0 -368
  24. package/dist/js/treeshaking/compilers/typescript/index.js +0 -339
  25. package/dist/js/treeshaking/compilers/typescript/tsconfig-paths-plugin.js +0 -246
  26. package/dist/js/treeshaking/compilers/typescript/typescript-loader.js +0 -65
  27. package/dist/js/treeshaking/index.js +0 -3
  28. /package/dist/esm/compilers/typescript/{tsconfig-paths-plugin.js → tsconfigPathsPlugin.js} +0 -0
  29. /package/dist/esm/compilers/typescript/{typescript-loader.js → typescriptLoader.js} +0 -0
  30. /package/dist/esm-node/compilers/typescript/{tsconfig-paths-plugin.js → tsconfigPathsPlugin.js} +0 -0
  31. /package/dist/esm-node/compilers/typescript/{typescript-loader.js → typescriptLoader.js} +0 -0
  32. /package/dist/types/compilers/typescript/{tsconfig-paths-plugin.d.ts → tsconfigPathsPlugin.d.ts} +0 -0
  33. /package/dist/types/compilers/typescript/{typescript-loader.d.ts → typescriptLoader.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @modern-js/server-utils
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 84bfb439b8: feat: support custom apiDir, lambdaDir and style of writing for bff
8
+ feat: 支持定制 api 目录,lambda 目录,bff 的写法
9
+
10
+ ### Patch Changes
11
+
12
+ - 7fff9020e1: chore: make file naming consistent
13
+
14
+ chore: 统一文件命名为小驼峰格式
15
+
16
+ - Updated dependencies [0f15fc597c]
17
+ - Updated dependencies [dcad887024]
18
+ - Updated dependencies [a4672f7c16]
19
+ - Updated dependencies [7fff9020e1]
20
+ - Updated dependencies [84bfb439b8]
21
+ - @modern-js/utils@2.7.0
22
+ - @modern-js/babel-preset-lib@2.7.0
23
+ - @modern-js/babel-compiler@2.7.0
24
+
25
+ ## 2.6.0
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [e1f799e]
30
+ - Updated dependencies [7915ab3]
31
+ - Updated dependencies [0fe658a]
32
+ - @modern-js/utils@2.6.0
33
+ - @modern-js/babel-preset-lib@2.6.0
34
+ - @modern-js/babel-compiler@2.6.0
35
+
3
36
  ## 2.5.0
4
37
 
5
38
  ### Patch Changes
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  };
19
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -29,8 +33,8 @@ module.exports = __toCommonJS(typescript_exports);
29
33
  var import_path = __toESM(require("path"));
30
34
  var import_utils = require("@modern-js/utils");
31
35
  var import_typescript = __toESM(require("typescript"));
32
- var import_typescript_loader = require("./typescript-loader");
33
- var import_tsconfig_paths_plugin = require("./tsconfig-paths-plugin");
36
+ var import_typescriptLoader = require("./typescriptLoader");
37
+ var import_tsconfigPathsPlugin = require("./tsconfigPathsPlugin");
34
38
  const readTsConfigByFile = (tsConfigFile) => {
35
39
  const parsedCmd = import_typescript.default.getParsedCommandLineOfConfigFile(
36
40
  tsConfigFile,
@@ -55,7 +59,7 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
55
59
  if (!tsconfigPath) {
56
60
  return;
57
61
  }
58
- const ts2 = new import_typescript_loader.TypescriptLoader({
62
+ const ts2 = new import_typescriptLoader.TypescriptLoader({
59
63
  appDirectory
60
64
  }).load();
61
65
  const createProgram = ts2.createIncrementalProgram || ts2.createProgram;
@@ -84,7 +88,7 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
84
88
  ...options
85
89
  }
86
90
  });
87
- const tsconfigPathsPlugin = (0, import_tsconfig_paths_plugin.tsconfigPathsBeforeHookFactory)(
91
+ const tsconfigPathsPlugin = (0, import_tsconfigPathsPlugin.tsconfigPathsBeforeHookFactory)(
88
92
  ts2,
89
93
  absoluteBaseUrl,
90
94
  paths
@@ -17,15 +17,19 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
23
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var tsconfig_paths_plugin_exports = {};
25
- __export(tsconfig_paths_plugin_exports, {
28
+ var tsconfigPathsPlugin_exports = {};
29
+ __export(tsconfigPathsPlugin_exports, {
26
30
  tsconfigPathsBeforeHookFactory: () => tsconfigPathsBeforeHookFactory
27
31
  });
28
- module.exports = __toCommonJS(tsconfig_paths_plugin_exports);
32
+ module.exports = __toCommonJS(tsconfigPathsPlugin_exports);
29
33
  var os = __toESM(require("os"));
30
34
  var import_path = __toESM(require("path"));
31
35
  var ts = __toESM(require("typescript"));
@@ -15,11 +15,11 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var typescript_loader_exports = {};
19
- __export(typescript_loader_exports, {
18
+ var typescriptLoader_exports = {};
19
+ __export(typescriptLoader_exports, {
20
20
  TypescriptLoader: () => TypescriptLoader
21
21
  });
22
- module.exports = __toCommonJS(typescript_loader_exports);
22
+ module.exports = __toCommonJS(typescriptLoader_exports);
23
23
  class TypescriptLoader {
24
24
  constructor({ appDirectory }) {
25
25
  this.appDirectory = appDirectory;
@@ -153,8 +153,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
153
153
  import path from "path";
154
154
  import { logger, getAliasConfig, fs } from "@modern-js/utils";
155
155
  import ts from "typescript";
156
- import { TypescriptLoader } from "./typescript-loader";
157
- import { tsconfigPathsBeforeHookFactory } from "./tsconfig-paths-plugin";
156
+ import { TypescriptLoader } from "./typescriptLoader";
157
+ import { tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin";
158
158
  var readTsConfigByFile = function(tsConfigFile) {
159
159
  var parsedCmd = ts.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, ts.sys);
160
160
  var options = parsedCmd.options, fileNames = parsedCmd.fileNames, projectReferences = parsedCmd.projectReferences;
@@ -1,8 +1,8 @@
1
1
  import path from "path";
2
2
  import { logger, getAliasConfig, fs } from "@modern-js/utils";
3
3
  import ts from "typescript";
4
- import { TypescriptLoader } from "./typescript-loader";
5
- import { tsconfigPathsBeforeHookFactory } from "./tsconfig-paths-plugin";
4
+ import { TypescriptLoader } from "./typescriptLoader";
5
+ import { tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin";
6
6
  const readTsConfigByFile = (tsConfigFile) => {
7
7
  const parsedCmd = ts.getParsedCommandLineOfConfigFile(
8
8
  tsConfigFile,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.5.1-alpha.0",
14
+ "version": "2.7.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -33,22 +33,22 @@
33
33
  "@babel/preset-env": "^7.18.0",
34
34
  "@babel/preset-typescript": "^7.17.12",
35
35
  "@babel/runtime": "^7.18.0",
36
- "@modern-js/babel-compiler": "2.5.0",
37
- "@modern-js/babel-preset-lib": "2.5.0",
38
- "@modern-js/utils": "2.5.0",
39
36
  "babel-plugin-module-resolver": "^4.1.0",
40
- "babel-plugin-transform-typescript-metadata": "^0.3.2"
37
+ "babel-plugin-transform-typescript-metadata": "^0.3.2",
38
+ "@modern-js/babel-compiler": "2.7.0",
39
+ "@modern-js/babel-preset-lib": "2.7.0",
40
+ "@modern-js/utils": "2.7.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@modern-js/server-core": "2.5.1-alpha.0",
44
- "@scripts/build": "2.5.0",
45
- "@scripts/jest-config": "2.5.0",
46
43
  "@types/babel__core": "^7.1.15",
47
44
  "@types/jest": "^27",
48
45
  "@types/node": "^14",
49
46
  "jest": "^27",
50
47
  "ts-jest": "^27.0.4",
51
- "typescript": "^4"
48
+ "typescript": "^4",
49
+ "@modern-js/server-core": "2.7.0",
50
+ "@scripts/build": "2.7.0",
51
+ "@scripts/jest-config": "2.7.0"
52
52
  },
53
53
  "sideEffects": false,
54
54
  "publishConfig": {
@@ -1,55 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import * as path from "path";
22
- import { fs } from "@modern-js/utils";
23
- import { compileByTs } from "../compilers/typescript";
24
- import { compileByBabel } from "../compilers/babel";
25
- const FILE_EXTENSIONS = [".js", ".ts", ".mjs", ".ejs"];
26
- const validateAbsolutePath = (filename, message) => {
27
- if (!path.isAbsolute(filename)) {
28
- throw new Error(message);
29
- }
30
- };
31
- const validateAbsolutePaths = (filenames, messageFunc) => {
32
- filenames.forEach(
33
- (filename) => validateAbsolutePath(filename, messageFunc(filename))
34
- );
35
- };
36
- const compile = (appDirectory, modernConfig, compileOptions) => __async(void 0, null, function* () {
37
- var _a;
38
- const { sourceDirs, distDir, tsconfigPath } = compileOptions;
39
- validateAbsolutePaths(
40
- sourceDirs,
41
- (dir) => `source dir ${dir} is not an absolute path.`
42
- );
43
- validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
44
- const compiler = (_a = modernConfig == null ? void 0 : modernConfig.server) == null ? void 0 : _a.compiler;
45
- const isTsProject = tsconfigPath && (yield fs.pathExists(tsconfigPath));
46
- if (!isTsProject || compiler === "babel") {
47
- yield compileByBabel(appDirectory, modernConfig, compileOptions);
48
- } else {
49
- yield compileByTs(appDirectory, modernConfig, compileOptions);
50
- }
51
- });
52
- export {
53
- FILE_EXTENSIONS,
54
- compile
55
- };
@@ -1,149 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
- import * as path from "path";
41
- import {
42
- getBabelChain,
43
- applyUserBabelConfig
44
- } from "@modern-js/babel-preset-lib";
45
- import { fs, json5, getAliasConfig } from "@modern-js/utils";
46
- import { compiler } from "@modern-js/babel-compiler";
47
- import { FILE_EXTENSIONS } from "../../common";
48
- export * from "@babel/core";
49
- const readTsConfig = (tsconfigPath, noExistReturn = null) => {
50
- if (!fs.existsSync(tsconfigPath)) {
51
- return noExistReturn;
52
- }
53
- const content = fs.readFileSync(tsconfigPath, "utf-8");
54
- return json5.parse(content);
55
- };
56
- const existTsConfigFile = (tsconfigAbsolutePath) => {
57
- const tsconfig = readTsConfig(tsconfigAbsolutePath);
58
- return Boolean(tsconfig);
59
- };
60
- const getBabelConfig = (libPresetOption, syntaxOption) => {
61
- const chain = getBabelChain(libPresetOption, syntaxOption);
62
- return __spreadValues({
63
- sourceType: "unambiguous"
64
- }, chain.toJSON());
65
- };
66
- const resolveBabelConfig = (appDirectory, config, option) => {
67
- const { globalVars, alias, babelConfig, define } = config;
68
- const globalDefineVars = define && Object.entries(define).reduce((object, [key, value]) => {
69
- object[key] = JSON.stringify(value);
70
- return object;
71
- }, {});
72
- const aliasConfig = getAliasConfig(alias, __spreadValues({
73
- appDirectory
74
- }, option));
75
- const babelChain = getBabelChain(
76
- {
77
- appDirectory,
78
- enableReactPreset: true,
79
- enableTypescriptPreset: true,
80
- alias: aliasConfig,
81
- envVars: [],
82
- globalVars: __spreadValues(__spreadValues({}, globalVars), globalDefineVars)
83
- },
84
- {
85
- type: option.type,
86
- syntax: option.syntax
87
- }
88
- );
89
- const envOptions = babelChain.preset("@babel/preset-env").options();
90
- babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
91
- __spreadProps(__spreadValues({}, envOptions[0]), {
92
- loose: true
93
- })
94
- ]);
95
- babelChain.plugin("babel-plugin-transform-typescript-metadata").use(
96
- require.resolve("babel-plugin-transform-typescript-metadata"),
97
- []
98
- );
99
- babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
100
- { legacy: true }
101
- ]);
102
- babelChain.plugin("@babel/plugin-proposal-class-properties").use(require.resolve("@babel/plugin-proposal-class-properties"), [
103
- {
104
- loose: true
105
- }
106
- ]);
107
- const internalBabelConfig = __spreadValues({}, babelChain.toJSON());
108
- return applyUserBabelConfig(internalBabelConfig, babelConfig);
109
- };
110
- const compileByBabel = (appDirectory, config, compileOptions) => __async(void 0, null, function* () {
111
- const { sourceDirs, distDir, tsconfigPath } = compileOptions;
112
- const results = yield Promise.all(
113
- sourceDirs.map((sourceDir) => __async(void 0, null, function* () {
114
- const babelConfig = resolveBabelConfig(appDirectory, config, {
115
- tsconfigPath: tsconfigPath ? tsconfigPath : "",
116
- syntax: "es6+",
117
- type: "commonjs"
118
- });
119
- if (yield fs.pathExists(sourceDir)) {
120
- const basename = path.basename(sourceDir);
121
- const targetDir = path.join(distDir, basename);
122
- yield fs.copy(sourceDir, targetDir, {
123
- filter: (src) => ![".ts", ".js"].includes(path.extname(src)) && src !== tsconfigPath
124
- });
125
- }
126
- return compiler(
127
- {
128
- rootDir: appDirectory,
129
- distDir,
130
- sourceDir,
131
- extensions: FILE_EXTENSIONS
132
- },
133
- babelConfig
134
- );
135
- }))
136
- );
137
- results.forEach((result) => {
138
- if (result.code === 1) {
139
- throw new Error(result.message);
140
- }
141
- });
142
- });
143
- export {
144
- compileByBabel,
145
- existTsConfigFile,
146
- getBabelConfig,
147
- readTsConfig,
148
- resolveBabelConfig
149
- };
@@ -1,123 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __async = (__this, __arguments, generator) => {
18
- return new Promise((resolve, reject) => {
19
- var fulfilled = (value) => {
20
- try {
21
- step(generator.next(value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- };
26
- var rejected = (value) => {
27
- try {
28
- step(generator.throw(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
- step((generator = generator.apply(__this, __arguments)).next());
35
- });
36
- };
37
- import path from "path";
38
- import { logger, getAliasConfig, fs } from "@modern-js/utils";
39
- import ts from "typescript";
40
- import { TypescriptLoader } from "./typescript-loader";
41
- import { tsconfigPathsBeforeHookFactory } from "./tsconfig-paths-plugin";
42
- const readTsConfigByFile = (tsConfigFile) => {
43
- const parsedCmd = ts.getParsedCommandLineOfConfigFile(
44
- tsConfigFile,
45
- void 0,
46
- ts.sys
47
- );
48
- const { options, fileNames, projectReferences } = parsedCmd;
49
- return { options, fileNames, projectReferences };
50
- };
51
- const copyFiles = (from, to, tsconfigPath) => __async(void 0, null, function* () {
52
- if (yield fs.pathExists(from)) {
53
- const basename = path.basename(from);
54
- const targetDir = path.join(to, basename);
55
- yield fs.copy(from, targetDir, {
56
- filter: (src) => ![".ts"].includes(path.extname(src)) && src !== tsconfigPath
57
- });
58
- }
59
- });
60
- const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, null, function* () {
61
- logger.info(`Running ts compile...`);
62
- const { sourceDirs, distDir, tsconfigPath } = compileOptions;
63
- if (!tsconfigPath) {
64
- return;
65
- }
66
- const ts2 = new TypescriptLoader({
67
- appDirectory
68
- }).load();
69
- const createProgram = ts2.createIncrementalProgram || ts2.createProgram;
70
- const formatHost = getFormatHost(ts2);
71
- const { alias } = config;
72
- const aliasOption = getAliasConfig(alias, {
73
- appDirectory,
74
- tsconfigPath
75
- });
76
- const { paths = {}, absoluteBaseUrl = "./" } = aliasOption;
77
- const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath);
78
- const sourcePosixPaths = sourceDirs.map(
79
- (sourceDir) => sourceDir.split(path.sep).join(path.posix.sep)
80
- );
81
- const rootNames = fileNames.filter((fileName) => {
82
- return fileName.endsWith(".d.ts") || sourcePosixPaths.some((sourceDir) => {
83
- return fileName.includes(sourceDir);
84
- });
85
- });
86
- const program = createProgram.call(ts2, {
87
- rootNames,
88
- projectReferences,
89
- options: __spreadValues({
90
- rootDir: appDirectory,
91
- outDir: distDir
92
- }, options)
93
- });
94
- const tsconfigPathsPlugin = tsconfigPathsBeforeHookFactory(
95
- ts2,
96
- absoluteBaseUrl,
97
- paths
98
- );
99
- const emitResult = program.emit(void 0, void 0, void 0, void 0, {
100
- before: [tsconfigPathsPlugin]
101
- });
102
- const allDiagnostics = ts2.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
103
- if (allDiagnostics.length > 0) {
104
- logger.error(
105
- ts2.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost)
106
- );
107
- process.exit(1);
108
- }
109
- for (const source of sourceDirs) {
110
- yield copyFiles(source, distDir, tsconfigPath);
111
- }
112
- logger.info(`Ts compile succeed`);
113
- });
114
- const getFormatHost = (ts2) => {
115
- return {
116
- getCanonicalFileName: (path2) => path2,
117
- getCurrentDirectory: ts2.sys.getCurrentDirectory,
118
- getNewLine: () => ts2.sys.newLine
119
- };
120
- };
121
- export {
122
- compileByTs
123
- };