@faasjs/load 0.0.3-beta.38 → 0.0.3-beta.40

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,34 +25,8 @@ __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");
@@ -73,11 +47,11 @@ var Config = class {
73
47
  configs.push((0, import_js_yaml.load)((0, import_fs.readFileSync)(faas).toString()));
74
48
  return root2;
75
49
  });
76
- this.origin = deepMerge(...configs);
77
- 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 || {});
78
52
  for (const key in this.origin) {
79
53
  if (key !== "defaults")
80
- this[key] = deepMerge(this.origin.defaults, this.origin[key]);
54
+ this[key] = (0, import_deep_merge.deepMerge)(this.origin.defaults, this.origin[key]);
81
55
  const data = this[key];
82
56
  if (data.plugins)
83
57
  for (const pluginKey in data.plugins) {
@@ -89,7 +63,7 @@ var Config = class {
89
63
  throw Error(`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`);
90
64
  plugin.provider = data.providers[plugin.provider];
91
65
  } else
92
- plugin.provider = deepMerge(data.providers[plugin.provider], plugin.provider);
66
+ plugin.provider = (0, import_deep_merge.deepMerge)(data.providers[plugin.provider], plugin.provider);
93
67
  }
94
68
  }
95
69
  }
@@ -99,86 +73,11 @@ function loadConfig(root, filename) {
99
73
  }
100
74
 
101
75
  // src/load_ts.ts
102
- var import_fs3 = require("fs");
103
- var import_rollup = require("rollup/dist/rollup.js");
104
- var import_path3 = require("path");
105
-
106
- // ../ts-transform/src/index.ts
107
- var import_core = require("@swc/core");
108
- var import_spack = require("@swc/core/spack");
76
+ var import_deep_merge2 = require("@faasjs/deep_merge");
109
77
  var import_fs2 = require("fs");
78
+ var import_rollup = require("rollup/dist/rollup.js");
110
79
  var import_path2 = require("path");
111
- var NodeBuiltinModules = [
112
- "async_hooks",
113
- "child_process",
114
- "cluster",
115
- "crypto",
116
- "dns",
117
- "events",
118
- "fs",
119
- "http",
120
- "http2",
121
- "https",
122
- "inspector",
123
- "net",
124
- "os",
125
- "path",
126
- "perf_hooks",
127
- "process",
128
- "querystring",
129
- "readline",
130
- "repl",
131
- "stream",
132
- "string_decoder",
133
- "tls",
134
- "trace_events",
135
- "tty",
136
- "dgram",
137
- "udp4",
138
- "url",
139
- "util",
140
- "v8",
141
- "vm",
142
- "wasi",
143
- "worker_threads",
144
- "zlib"
145
- ];
146
- async function bundle(options) {
147
- var _a;
148
- if (!options.root)
149
- options.root = process.cwd();
150
- if (!options.jscTarget)
151
- options.jscTarget = "es2019";
152
- const tsconfig = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(options.root, "tsconfig.json")).toString());
153
- if (!tsconfig.compilerOptions)
154
- tsconfig.compilerOptions = {};
155
- tsconfig.compilerOptions.baseUrl = ((_a = tsconfig.compilerOptions.baseUrl) == null ? void 0 : _a.replace(".", options.root)) || options.root;
156
- if (tsconfig.compilerOptions.paths) {
157
- for (const key of Object.keys(tsconfig.compilerOptions.paths))
158
- tsconfig.compilerOptions.paths[key] = tsconfig.compilerOptions.paths[key].map((item) => item.replace(".", tsconfig.compilerOptions.baseUrl));
159
- } else
160
- tsconfig.compilerOptions.paths = {};
161
- return (0, import_core.bundle)((0, import_spack.config)(deepMerge({
162
- mode: "production",
163
- entry: { index: options.filename },
164
- module: { type: "commonjs" },
165
- options: {
166
- jsc: {
167
- parser: {
168
- syntax: "typescript",
169
- tsx: true
170
- },
171
- target: options.jscTarget,
172
- baseUrl: tsconfig.compilerOptions.baseUrl,
173
- paths: tsconfig.compilerOptions.paths,
174
- transform: { react: { runtime: "automatic" } }
175
- }
176
- },
177
- externalModules: NodeBuiltinModules.concat(options.externalModules || [])
178
- }, options))).then((res) => res.index);
179
- }
180
-
181
- // src/load_ts.ts
80
+ var import_ts_transform = require("@faasjs/ts-transform");
182
81
  var FaasPackages = [
183
82
  "@faasjs/cloud_function",
184
83
  "@faasjs/deep_merge",
@@ -200,10 +99,10 @@ function resolveModuleBasePath(moduleName) {
200
99
  let searchForPathSection;
201
100
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
202
101
  const [org, mod] = moduleNameParts;
203
- searchForPathSection = `node_modules${import_path3.sep}${org}${import_path3.sep}${mod}`;
102
+ searchForPathSection = `node_modules${import_path2.sep}${org}${import_path2.sep}${mod}`;
204
103
  } else {
205
104
  const [mod] = moduleNameParts;
206
- searchForPathSection = `node_modules${import_path3.sep}${mod}`;
105
+ searchForPathSection = `node_modules${import_path2.sep}${mod}`;
207
106
  }
208
107
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
209
108
  if (lastIndex === -1) {
@@ -218,7 +117,7 @@ function findModule(list, key, options = { excludes: [] }) {
218
117
  if (key.startsWith("@types/") || options.excludes.includes(key))
219
118
  return;
220
119
  try {
221
- 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")));
222
121
  } catch (error) {
223
122
  console.warn(error);
224
123
  try {
@@ -229,7 +128,7 @@ function findModule(list, key, options = { excludes: [] }) {
229
128
  }
230
129
  if (!list[key])
231
130
  return;
232
- 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());
233
132
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
234
133
  if (pkg.peerDependenciesMeta) {
235
134
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -246,7 +145,7 @@ function swc(externalModules) {
246
145
  return {
247
146
  name: "swc",
248
147
  async transform(code, filename) {
249
- return bundle({
148
+ return (0, import_ts_transform.bundle)({
250
149
  filename,
251
150
  externalModules
252
151
  });
@@ -259,7 +158,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
259
158
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
260
159
  if (options.modules && options.modules.excludes == null)
261
160
  options.modules.excludes = [];
262
- const input = deepMerge({
161
+ const input = (0, import_deep_merge2.deepMerge)({
263
162
  input: filename,
264
163
  external,
265
164
  plugins: [swc(external.concat(FaasPackages))],
@@ -269,9 +168,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
269
168
  const dependencies = /* @__PURE__ */ Object.create(null);
270
169
  for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
271
170
  for (const d of m.dependencies)
272
- if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
171
+ if (!d.startsWith("/") && !dependencies[d] && !import_ts_transform.NodeBuiltinModules.includes(d))
273
172
  dependencies[d] = "*";
274
- const output = deepMerge({
173
+ const output = (0, import_deep_merge2.deepMerge)({
275
174
  file: filename + ".tmp.js",
276
175
  format: "cjs",
277
176
  exports: "auto"
@@ -281,7 +180,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
281
180
  result.dependencies = dependencies;
282
181
  result.module = require(output.file);
283
182
  if (options.tmp)
284
- (0, import_fs3.unlinkSync)(output.file);
183
+ (0, import_fs2.unlinkSync)(output.file);
285
184
  if (options.modules) {
286
185
  const modules = /* @__PURE__ */ Object.create(null);
287
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,
@@ -84,93 +58,15 @@ function loadConfig(root, filename) {
84
58
  }
85
59
 
86
60
  // src/load_ts.ts
87
- import { readFileSync as readFileSync3, unlinkSync } from "fs";
61
+ import { deepMerge as deepMerge2 } from "@faasjs/deep_merge";
62
+ import { readFileSync as readFileSync2, unlinkSync } from "fs";
88
63
  import { rollup } from "rollup/dist/rollup.js";
89
64
  import {
90
- join as join3,
65
+ join as join2,
91
66
  sep as sep2,
92
67
  dirname as dirname2
93
68
  } from "path";
94
-
95
- // ../ts-transform/src/index.ts
96
- import {
97
- transformSync,
98
- bundle as swcBundle
99
- } from "@swc/core";
100
- import { config } from "@swc/core/spack";
101
- import { readFileSync as readFileSync2 } from "fs";
102
- import { join as join2 } from "path";
103
- var NodeBuiltinModules = [
104
- "async_hooks",
105
- "child_process",
106
- "cluster",
107
- "crypto",
108
- "dns",
109
- "events",
110
- "fs",
111
- "http",
112
- "http2",
113
- "https",
114
- "inspector",
115
- "net",
116
- "os",
117
- "path",
118
- "perf_hooks",
119
- "process",
120
- "querystring",
121
- "readline",
122
- "repl",
123
- "stream",
124
- "string_decoder",
125
- "tls",
126
- "trace_events",
127
- "tty",
128
- "dgram",
129
- "udp4",
130
- "url",
131
- "util",
132
- "v8",
133
- "vm",
134
- "wasi",
135
- "worker_threads",
136
- "zlib"
137
- ];
138
- async function bundle(options) {
139
- var _a;
140
- if (!options.root)
141
- options.root = process.cwd();
142
- if (!options.jscTarget)
143
- options.jscTarget = "es2019";
144
- const tsconfig = JSON.parse(readFileSync2(join2(options.root, "tsconfig.json")).toString());
145
- if (!tsconfig.compilerOptions)
146
- tsconfig.compilerOptions = {};
147
- tsconfig.compilerOptions.baseUrl = ((_a = tsconfig.compilerOptions.baseUrl) == null ? void 0 : _a.replace(".", options.root)) || options.root;
148
- if (tsconfig.compilerOptions.paths) {
149
- for (const key of Object.keys(tsconfig.compilerOptions.paths))
150
- tsconfig.compilerOptions.paths[key] = tsconfig.compilerOptions.paths[key].map((item) => item.replace(".", tsconfig.compilerOptions.baseUrl));
151
- } else
152
- tsconfig.compilerOptions.paths = {};
153
- return swcBundle(config(deepMerge({
154
- mode: "production",
155
- entry: { index: options.filename },
156
- module: { type: "commonjs" },
157
- options: {
158
- jsc: {
159
- parser: {
160
- syntax: "typescript",
161
- tsx: true
162
- },
163
- target: options.jscTarget,
164
- baseUrl: tsconfig.compilerOptions.baseUrl,
165
- paths: tsconfig.compilerOptions.paths,
166
- transform: { react: { runtime: "automatic" } }
167
- }
168
- },
169
- externalModules: NodeBuiltinModules.concat(options.externalModules || [])
170
- }, options))).then((res) => res.index);
171
- }
172
-
173
- // src/load_ts.ts
69
+ import { bundle, NodeBuiltinModules } from "@faasjs/ts-transform";
174
70
  var FaasPackages = [
175
71
  "@faasjs/cloud_function",
176
72
  "@faasjs/deep_merge",
@@ -210,7 +106,7 @@ function findModule(list, key, options = { excludes: [] }) {
210
106
  if (key.startsWith("@types/") || options.excludes.includes(key))
211
107
  return;
212
108
  try {
213
- list[key] = dirname2(__require.resolve(join3(key, "package.json")));
109
+ list[key] = dirname2(__require.resolve(join2(key, "package.json")));
214
110
  } catch (error) {
215
111
  console.warn(error);
216
112
  try {
@@ -221,7 +117,7 @@ function findModule(list, key, options = { excludes: [] }) {
221
117
  }
222
118
  if (!list[key])
223
119
  return;
224
- const pkg = JSON.parse(readFileSync3(join3(list[key], "package.json")).toString());
120
+ const pkg = JSON.parse(readFileSync2(join2(list[key], "package.json")).toString());
225
121
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
226
122
  if (pkg.peerDependenciesMeta) {
227
123
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -251,7 +147,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
251
147
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
252
148
  if (options.modules && options.modules.excludes == null)
253
149
  options.modules.excludes = [];
254
- const input = deepMerge({
150
+ const input = deepMerge2({
255
151
  input: filename,
256
152
  external,
257
153
  plugins: [swc(external.concat(FaasPackages))],
@@ -263,7 +159,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
263
159
  for (const d of m.dependencies)
264
160
  if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
265
161
  dependencies[d] = "*";
266
- const output = deepMerge({
162
+ const output = deepMerge2({
267
163
  file: filename + ".tmp.js",
268
164
  format: "cjs",
269
165
  exports: "auto"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "0.0.3-beta.38",
3
+ "version": "0.0.3-beta.40",
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.38",
26
- "@faasjs/func": "^0.0.3-beta.38",
27
- "@faasjs/ts-transform": "^0.0.3-beta.38",
25
+ "@faasjs/deep_merge": "^0.0.3-beta.40",
26
+ "@faasjs/func": "^0.0.3-beta.40",
27
+ "@faasjs/ts-transform": "^0.0.3-beta.40",
28
28
  "js-yaml": "*",
29
29
  "rollup": "*"
30
30
  },