@faasjs/load 0.0.3-beta.64 → 0.0.3-beta.66

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/dist/index.js CHANGED
@@ -25,44 +25,12 @@ __export(src_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
- // ../deep_merge/src/index.ts
29
- var shouldMerge = function(item) {
30
- const type = Object.prototype.toString.call(item);
31
- return type === "[object Object]" || type === "[object Array]";
32
- };
33
- function deepMerge(...sources) {
34
- let acc = /* @__PURE__ */ Object.create(null);
35
- for (const source of sources)
36
- if (source instanceof Array) {
37
- if (!(acc instanceof Array))
38
- acc = [];
39
- acc = [...new Set(source.concat(...acc))];
40
- } else if (shouldMerge(source))
41
- for (const [key, value] of Object.entries(source)) {
42
- let val;
43
- if (shouldMerge(value))
44
- val = deepMerge(acc[key], value);
45
- else
46
- val = value;
47
- acc = {
48
- ...acc,
49
- [key]: val
50
- };
51
- }
52
- return acc;
53
- }
54
-
55
28
  // src/load_config.ts
29
+ var import_deep_merge = require("@faasjs/deep_merge");
56
30
  var import_fs = require("fs");
57
31
  var import_path = require("path");
58
32
  var import_js_yaml = require("js-yaml");
59
33
  var Config = class {
60
- /**
61
- * 创建配置类,并自动读取配置内容
62
- *
63
- * @param root {string} 根目录
64
- * @param filename {filename} 目标文件,用于读取目录层级
65
- */
66
34
  constructor(root, filename) {
67
35
  this.root = root;
68
36
  if (!this.root.endsWith(import_path.sep))
@@ -79,11 +47,11 @@ var Config = class {
79
47
  configs.push((0, import_js_yaml.load)((0, import_fs.readFileSync)(faas).toString()));
80
48
  return root2;
81
49
  });
82
- this.origin = deepMerge(...configs);
83
- this.defaults = deepMerge(this.origin.defaults || {});
50
+ this.origin = (0, import_deep_merge.deepMerge)(...configs);
51
+ this.defaults = (0, import_deep_merge.deepMerge)(this.origin.defaults || {});
84
52
  for (const key in this.origin) {
85
53
  if (key !== "defaults")
86
- this[key] = deepMerge(this.origin.defaults, this.origin[key]);
54
+ this[key] = (0, import_deep_merge.deepMerge)(this.origin.defaults, this.origin[key]);
87
55
  const data = this[key];
88
56
  if (data.plugins)
89
57
  for (const pluginKey in data.plugins) {
@@ -95,7 +63,7 @@ var Config = class {
95
63
  throw Error(`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`);
96
64
  plugin.provider = data.providers[plugin.provider];
97
65
  } else
98
- plugin.provider = deepMerge(data.providers[plugin.provider], plugin.provider);
66
+ plugin.provider = (0, import_deep_merge.deepMerge)(data.providers[plugin.provider], plugin.provider);
99
67
  }
100
68
  }
101
69
  }
@@ -105,86 +73,11 @@ function loadConfig(root, filename) {
105
73
  }
106
74
 
107
75
  // src/load_ts.ts
108
- var import_fs3 = require("fs");
109
- var import_rollup = require("rollup/dist/rollup.js");
110
- var import_path3 = require("path");
111
-
112
- // ../ts-transform/src/index.ts
113
- var import_core = require("@swc/core");
114
- var import_spack = require("@swc/core/spack");
76
+ var import_deep_merge2 = require("@faasjs/deep_merge");
115
77
  var import_fs2 = require("fs");
78
+ var import_rollup = require("rollup/dist/rollup.js");
116
79
  var import_path2 = require("path");
117
- var NodeBuiltinModules = [
118
- "async_hooks",
119
- "child_process",
120
- "cluster",
121
- "crypto",
122
- "dns",
123
- "events",
124
- "fs",
125
- "http",
126
- "http2",
127
- "https",
128
- "inspector",
129
- "net",
130
- "os",
131
- "path",
132
- "perf_hooks",
133
- "process",
134
- "querystring",
135
- "readline",
136
- "repl",
137
- "stream",
138
- "string_decoder",
139
- "tls",
140
- "trace_events",
141
- "tty",
142
- "dgram",
143
- "udp4",
144
- "url",
145
- "util",
146
- "v8",
147
- "vm",
148
- "wasi",
149
- "worker_threads",
150
- "zlib"
151
- ];
152
- async function bundle(options) {
153
- var _a;
154
- if (!options.root)
155
- options.root = process.cwd();
156
- if (!options.jscTarget)
157
- options.jscTarget = "es2019";
158
- const tsconfig = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(options.root, "tsconfig.json")).toString());
159
- if (!tsconfig.compilerOptions)
160
- tsconfig.compilerOptions = {};
161
- tsconfig.compilerOptions.baseUrl = ((_a = tsconfig.compilerOptions.baseUrl) == null ? void 0 : _a.replace(".", options.root)) || options.root;
162
- if (tsconfig.compilerOptions.paths) {
163
- for (const key of Object.keys(tsconfig.compilerOptions.paths))
164
- tsconfig.compilerOptions.paths[key] = tsconfig.compilerOptions.paths[key].map((item) => item.replace(".", tsconfig.compilerOptions.baseUrl));
165
- } else
166
- tsconfig.compilerOptions.paths = {};
167
- return (0, import_core.bundle)((0, import_spack.config)(deepMerge({
168
- mode: "production",
169
- entry: { index: options.filename },
170
- module: { type: "commonjs" },
171
- options: {
172
- jsc: {
173
- parser: {
174
- syntax: "typescript",
175
- tsx: true
176
- },
177
- target: options.jscTarget,
178
- baseUrl: tsconfig.compilerOptions.baseUrl,
179
- paths: tsconfig.compilerOptions.paths,
180
- transform: { react: { runtime: "automatic" } }
181
- }
182
- },
183
- externalModules: NodeBuiltinModules.concat(options.externalModules || [])
184
- }, options))).then((res) => res.index);
185
- }
186
-
187
- // src/load_ts.ts
80
+ var import_ts_transform = require("@faasjs/ts-transform");
188
81
  var FaasPackages = [
189
82
  "@faasjs/cloud_function",
190
83
  "@faasjs/deep_merge",
@@ -206,10 +99,10 @@ function resolveModuleBasePath(moduleName) {
206
99
  let searchForPathSection;
207
100
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
208
101
  const [org, mod] = moduleNameParts;
209
- searchForPathSection = `node_modules${import_path3.sep}${org}${import_path3.sep}${mod}`;
102
+ searchForPathSection = `node_modules${import_path2.sep}${org}${import_path2.sep}${mod}`;
210
103
  } else {
211
104
  const [mod] = moduleNameParts;
212
- searchForPathSection = `node_modules${import_path3.sep}${mod}`;
105
+ searchForPathSection = `node_modules${import_path2.sep}${mod}`;
213
106
  }
214
107
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
215
108
  if (lastIndex === -1) {
@@ -224,7 +117,7 @@ function findModule(list, key, options = { excludes: [] }) {
224
117
  if (key.startsWith("@types/") || options.excludes.includes(key))
225
118
  return;
226
119
  try {
227
- list[key] = (0, import_path3.dirname)(require.resolve((0, import_path3.join)(key, "package.json")));
120
+ list[key] = (0, import_path2.dirname)(require.resolve((0, import_path2.join)(key, "package.json")));
228
121
  } catch (error) {
229
122
  console.warn(error);
230
123
  try {
@@ -235,7 +128,7 @@ function findModule(list, key, options = { excludes: [] }) {
235
128
  }
236
129
  if (!list[key])
237
130
  return;
238
- const pkg = JSON.parse((0, import_fs3.readFileSync)((0, import_path3.join)(list[key], "package.json")).toString());
131
+ const pkg = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(list[key], "package.json")).toString());
239
132
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
240
133
  if (pkg.peerDependenciesMeta) {
241
134
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -252,7 +145,7 @@ function swc(externalModules) {
252
145
  return {
253
146
  name: "swc",
254
147
  async transform(code, filename) {
255
- return bundle({
148
+ return (0, import_ts_transform.bundle)({
256
149
  filename,
257
150
  externalModules
258
151
  });
@@ -265,7 +158,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
265
158
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
266
159
  if (options.modules && options.modules.excludes == null)
267
160
  options.modules.excludes = [];
268
- const input = deepMerge({
161
+ const input = (0, import_deep_merge2.deepMerge)({
269
162
  input: filename,
270
163
  external,
271
164
  plugins: [swc(external.concat(FaasPackages))],
@@ -275,9 +168,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
275
168
  const dependencies = /* @__PURE__ */ Object.create(null);
276
169
  for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
277
170
  for (const d of m.dependencies)
278
- if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
171
+ if (!d.startsWith("/") && !dependencies[d] && !import_ts_transform.NodeBuiltinModules.includes(d))
279
172
  dependencies[d] = "*";
280
- const output = deepMerge({
173
+ const output = (0, import_deep_merge2.deepMerge)({
281
174
  file: filename + ".tmp.js",
282
175
  format: "cjs",
283
176
  exports: "auto"
@@ -287,7 +180,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
287
180
  result.dependencies = dependencies;
288
181
  result.module = require(output.file);
289
182
  if (options.tmp)
290
- (0, import_fs3.unlinkSync)(output.file);
183
+ (0, import_fs2.unlinkSync)(output.file);
291
184
  if (options.modules) {
292
185
  const modules = /* @__PURE__ */ Object.create(null);
293
186
  Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
package/dist/index.mjs CHANGED
@@ -6,34 +6,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  throw new Error('Dynamic require of "' + x + '" is not supported');
7
7
  });
8
8
 
9
- // ../deep_merge/src/index.ts
10
- var shouldMerge = function(item) {
11
- const type = Object.prototype.toString.call(item);
12
- return type === "[object Object]" || type === "[object Array]";
13
- };
14
- function deepMerge(...sources) {
15
- let acc = /* @__PURE__ */ Object.create(null);
16
- for (const source of sources)
17
- if (source instanceof Array) {
18
- if (!(acc instanceof Array))
19
- acc = [];
20
- acc = [...new Set(source.concat(...acc))];
21
- } else if (shouldMerge(source))
22
- for (const [key, value] of Object.entries(source)) {
23
- let val;
24
- if (shouldMerge(value))
25
- val = deepMerge(acc[key], value);
26
- else
27
- val = value;
28
- acc = {
29
- ...acc,
30
- [key]: val
31
- };
32
- }
33
- return acc;
34
- }
35
-
36
9
  // src/load_config.ts
10
+ import { deepMerge } from "@faasjs/deep_merge";
37
11
  import { existsSync, readFileSync } from "fs";
38
12
  import {
39
13
  sep,
@@ -42,12 +16,6 @@ import {
42
16
  } from "path";
43
17
  import { load } from "js-yaml";
44
18
  var Config = class {
45
- /**
46
- * 创建配置类,并自动读取配置内容
47
- *
48
- * @param root {string} 根目录
49
- * @param filename {filename} 目标文件,用于读取目录层级
50
- */
51
19
  constructor(root, filename) {
52
20
  this.root = root;
53
21
  if (!this.root.endsWith(sep))
@@ -90,93 +58,15 @@ function loadConfig(root, filename) {
90
58
  }
91
59
 
92
60
  // src/load_ts.ts
93
- import { readFileSync as readFileSync3, unlinkSync } from "fs";
61
+ import { deepMerge as deepMerge2 } from "@faasjs/deep_merge";
62
+ import { readFileSync as readFileSync2, unlinkSync } from "fs";
94
63
  import { rollup } from "rollup/dist/rollup.js";
95
64
  import {
96
- join as join3,
65
+ join as join2,
97
66
  sep as sep2,
98
67
  dirname as dirname2
99
68
  } from "path";
100
-
101
- // ../ts-transform/src/index.ts
102
- import {
103
- transformSync,
104
- bundle as swcBundle
105
- } from "@swc/core";
106
- import { config } from "@swc/core/spack";
107
- import { readFileSync as readFileSync2 } from "fs";
108
- import { join as join2 } from "path";
109
- var NodeBuiltinModules = [
110
- "async_hooks",
111
- "child_process",
112
- "cluster",
113
- "crypto",
114
- "dns",
115
- "events",
116
- "fs",
117
- "http",
118
- "http2",
119
- "https",
120
- "inspector",
121
- "net",
122
- "os",
123
- "path",
124
- "perf_hooks",
125
- "process",
126
- "querystring",
127
- "readline",
128
- "repl",
129
- "stream",
130
- "string_decoder",
131
- "tls",
132
- "trace_events",
133
- "tty",
134
- "dgram",
135
- "udp4",
136
- "url",
137
- "util",
138
- "v8",
139
- "vm",
140
- "wasi",
141
- "worker_threads",
142
- "zlib"
143
- ];
144
- async function bundle(options) {
145
- var _a;
146
- if (!options.root)
147
- options.root = process.cwd();
148
- if (!options.jscTarget)
149
- options.jscTarget = "es2019";
150
- const tsconfig = JSON.parse(readFileSync2(join2(options.root, "tsconfig.json")).toString());
151
- if (!tsconfig.compilerOptions)
152
- tsconfig.compilerOptions = {};
153
- tsconfig.compilerOptions.baseUrl = ((_a = tsconfig.compilerOptions.baseUrl) == null ? void 0 : _a.replace(".", options.root)) || options.root;
154
- if (tsconfig.compilerOptions.paths) {
155
- for (const key of Object.keys(tsconfig.compilerOptions.paths))
156
- tsconfig.compilerOptions.paths[key] = tsconfig.compilerOptions.paths[key].map((item) => item.replace(".", tsconfig.compilerOptions.baseUrl));
157
- } else
158
- tsconfig.compilerOptions.paths = {};
159
- return swcBundle(config(deepMerge({
160
- mode: "production",
161
- entry: { index: options.filename },
162
- module: { type: "commonjs" },
163
- options: {
164
- jsc: {
165
- parser: {
166
- syntax: "typescript",
167
- tsx: true
168
- },
169
- target: options.jscTarget,
170
- baseUrl: tsconfig.compilerOptions.baseUrl,
171
- paths: tsconfig.compilerOptions.paths,
172
- transform: { react: { runtime: "automatic" } }
173
- }
174
- },
175
- externalModules: NodeBuiltinModules.concat(options.externalModules || [])
176
- }, options))).then((res) => res.index);
177
- }
178
-
179
- // src/load_ts.ts
69
+ import { bundle, NodeBuiltinModules } from "@faasjs/ts-transform";
180
70
  var FaasPackages = [
181
71
  "@faasjs/cloud_function",
182
72
  "@faasjs/deep_merge",
@@ -216,7 +106,7 @@ function findModule(list, key, options = { excludes: [] }) {
216
106
  if (key.startsWith("@types/") || options.excludes.includes(key))
217
107
  return;
218
108
  try {
219
- list[key] = dirname2(__require.resolve(join3(key, "package.json")));
109
+ list[key] = dirname2(__require.resolve(join2(key, "package.json")));
220
110
  } catch (error) {
221
111
  console.warn(error);
222
112
  try {
@@ -227,7 +117,7 @@ function findModule(list, key, options = { excludes: [] }) {
227
117
  }
228
118
  if (!list[key])
229
119
  return;
230
- const pkg = JSON.parse(readFileSync3(join3(list[key], "package.json")).toString());
120
+ const pkg = JSON.parse(readFileSync2(join2(list[key], "package.json")).toString());
231
121
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
232
122
  if (pkg.peerDependenciesMeta) {
233
123
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -257,7 +147,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
257
147
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
258
148
  if (options.modules && options.modules.excludes == null)
259
149
  options.modules.excludes = [];
260
- const input = deepMerge({
150
+ const input = deepMerge2({
261
151
  input: filename,
262
152
  external,
263
153
  plugins: [swc(external.concat(FaasPackages))],
@@ -269,7 +159,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
269
159
  for (const d of m.dependencies)
270
160
  if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
271
161
  dependencies[d] = "*";
272
- const output = deepMerge({
162
+ const output = deepMerge2({
273
163
  file: filename + ".tmp.js",
274
164
  format: "cjs",
275
165
  exports: "auto"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "0.0.3-beta.64",
3
+ "version": "0.0.3-beta.66",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,9 +22,9 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@faasjs/deep_merge": "^0.0.3-beta.64",
26
- "@faasjs/func": "^0.0.3-beta.64",
27
- "@faasjs/ts-transform": "^0.0.3-beta.64",
25
+ "@faasjs/deep_merge": "^0.0.3-beta.66",
26
+ "@faasjs/func": "^0.0.3-beta.66",
27
+ "@faasjs/ts-transform": "^0.0.3-beta.66",
28
28
  "js-yaml": "*",
29
29
  "rollup": "*"
30
30
  },