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

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,8 +25,34 @@ __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
+
28
55
  // src/load_config.ts
29
- var import_deep_merge = require("@faasjs/deep_merge");
30
56
  var import_fs = require("fs");
31
57
  var import_path = require("path");
32
58
  var import_js_yaml = require("js-yaml");
@@ -47,11 +73,11 @@ var Config = class {
47
73
  configs.push((0, import_js_yaml.load)((0, import_fs.readFileSync)(faas).toString()));
48
74
  return root2;
49
75
  });
50
- this.origin = (0, import_deep_merge.deepMerge)(...configs);
51
- this.defaults = (0, import_deep_merge.deepMerge)(this.origin.defaults || {});
76
+ this.origin = deepMerge(...configs);
77
+ this.defaults = deepMerge(this.origin.defaults || {});
52
78
  for (const key in this.origin) {
53
79
  if (key !== "defaults")
54
- this[key] = (0, import_deep_merge.deepMerge)(this.origin.defaults, this.origin[key]);
80
+ this[key] = deepMerge(this.origin.defaults, this.origin[key]);
55
81
  const data = this[key];
56
82
  if (data.plugins)
57
83
  for (const pluginKey in data.plugins) {
@@ -63,7 +89,7 @@ var Config = class {
63
89
  throw Error(`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`);
64
90
  plugin.provider = data.providers[plugin.provider];
65
91
  } else
66
- plugin.provider = (0, import_deep_merge.deepMerge)(data.providers[plugin.provider], plugin.provider);
92
+ plugin.provider = deepMerge(data.providers[plugin.provider], plugin.provider);
67
93
  }
68
94
  }
69
95
  }
@@ -73,11 +99,86 @@ function loadConfig(root, filename) {
73
99
  }
74
100
 
75
101
  // src/load_ts.ts
76
- var import_deep_merge2 = require("@faasjs/deep_merge");
77
- var import_fs2 = require("fs");
102
+ var import_fs3 = require("fs");
78
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");
109
+ var import_fs2 = require("fs");
79
110
  var import_path2 = require("path");
80
- var import_ts_transform = require("@faasjs/ts-transform");
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
81
182
  var FaasPackages = [
82
183
  "@faasjs/cloud_function",
83
184
  "@faasjs/deep_merge",
@@ -99,10 +200,10 @@ function resolveModuleBasePath(moduleName) {
99
200
  let searchForPathSection;
100
201
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
101
202
  const [org, mod] = moduleNameParts;
102
- searchForPathSection = `node_modules${import_path2.sep}${org}${import_path2.sep}${mod}`;
203
+ searchForPathSection = `node_modules${import_path3.sep}${org}${import_path3.sep}${mod}`;
103
204
  } else {
104
205
  const [mod] = moduleNameParts;
105
- searchForPathSection = `node_modules${import_path2.sep}${mod}`;
206
+ searchForPathSection = `node_modules${import_path3.sep}${mod}`;
106
207
  }
107
208
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
108
209
  if (lastIndex === -1) {
@@ -117,7 +218,7 @@ function findModule(list, key, options = { excludes: [] }) {
117
218
  if (key.startsWith("@types/") || options.excludes.includes(key))
118
219
  return;
119
220
  try {
120
- list[key] = (0, import_path2.dirname)(require.resolve((0, import_path2.join)(key, "package.json")));
221
+ list[key] = (0, import_path3.dirname)(require.resolve((0, import_path3.join)(key, "package.json")));
121
222
  } catch (error) {
122
223
  console.warn(error);
123
224
  try {
@@ -128,7 +229,7 @@ function findModule(list, key, options = { excludes: [] }) {
128
229
  }
129
230
  if (!list[key])
130
231
  return;
131
- const pkg = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(list[key], "package.json")).toString());
232
+ const pkg = JSON.parse((0, import_fs3.readFileSync)((0, import_path3.join)(list[key], "package.json")).toString());
132
233
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
133
234
  if (pkg.peerDependenciesMeta) {
134
235
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -145,7 +246,7 @@ function swc(externalModules) {
145
246
  return {
146
247
  name: "swc",
147
248
  async transform(code, filename) {
148
- return (0, import_ts_transform.bundle)({
249
+ return bundle({
149
250
  filename,
150
251
  externalModules
151
252
  });
@@ -158,7 +259,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
158
259
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
159
260
  if (options.modules && options.modules.excludes == null)
160
261
  options.modules.excludes = [];
161
- const input = (0, import_deep_merge2.deepMerge)({
262
+ const input = deepMerge({
162
263
  input: filename,
163
264
  external,
164
265
  plugins: [swc(external.concat(FaasPackages))],
@@ -168,9 +269,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
168
269
  const dependencies = /* @__PURE__ */ Object.create(null);
169
270
  for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
170
271
  for (const d of m.dependencies)
171
- if (!d.startsWith("/") && !dependencies[d] && !import_ts_transform.NodeBuiltinModules.includes(d))
272
+ if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
172
273
  dependencies[d] = "*";
173
- const output = (0, import_deep_merge2.deepMerge)({
274
+ const output = deepMerge({
174
275
  file: filename + ".tmp.js",
175
276
  format: "cjs",
176
277
  exports: "auto"
@@ -180,7 +281,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
180
281
  result.dependencies = dependencies;
181
282
  result.module = require(output.file);
182
283
  if (options.tmp)
183
- (0, import_fs2.unlinkSync)(output.file);
284
+ (0, import_fs3.unlinkSync)(output.file);
184
285
  if (options.modules) {
185
286
  const modules = /* @__PURE__ */ Object.create(null);
186
287
  Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
package/dist/index.mjs CHANGED
@@ -6,8 +6,34 @@ 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
+
9
36
  // src/load_config.ts
10
- import { deepMerge } from "@faasjs/deep_merge";
11
37
  import { existsSync, readFileSync } from "fs";
12
38
  import {
13
39
  sep,
@@ -58,15 +84,93 @@ function loadConfig(root, filename) {
58
84
  }
59
85
 
60
86
  // src/load_ts.ts
61
- import { deepMerge as deepMerge2 } from "@faasjs/deep_merge";
62
- import { readFileSync as readFileSync2, unlinkSync } from "fs";
87
+ import { readFileSync as readFileSync3, unlinkSync } from "fs";
63
88
  import { rollup } from "rollup/dist/rollup.js";
64
89
  import {
65
- join as join2,
90
+ join as join3,
66
91
  sep as sep2,
67
92
  dirname as dirname2
68
93
  } from "path";
69
- import { bundle, NodeBuiltinModules } from "@faasjs/ts-transform";
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
70
174
  var FaasPackages = [
71
175
  "@faasjs/cloud_function",
72
176
  "@faasjs/deep_merge",
@@ -106,7 +210,7 @@ function findModule(list, key, options = { excludes: [] }) {
106
210
  if (key.startsWith("@types/") || options.excludes.includes(key))
107
211
  return;
108
212
  try {
109
- list[key] = dirname2(__require.resolve(join2(key, "package.json")));
213
+ list[key] = dirname2(__require.resolve(join3(key, "package.json")));
110
214
  } catch (error) {
111
215
  console.warn(error);
112
216
  try {
@@ -117,7 +221,7 @@ function findModule(list, key, options = { excludes: [] }) {
117
221
  }
118
222
  if (!list[key])
119
223
  return;
120
- const pkg = JSON.parse(readFileSync2(join2(list[key], "package.json")).toString());
224
+ const pkg = JSON.parse(readFileSync3(join3(list[key], "package.json")).toString());
121
225
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
122
226
  if (pkg.peerDependenciesMeta) {
123
227
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -147,7 +251,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
147
251
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
148
252
  if (options.modules && options.modules.excludes == null)
149
253
  options.modules.excludes = [];
150
- const input = deepMerge2({
254
+ const input = deepMerge({
151
255
  input: filename,
152
256
  external,
153
257
  plugins: [swc(external.concat(FaasPackages))],
@@ -159,7 +263,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
159
263
  for (const d of m.dependencies)
160
264
  if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
161
265
  dependencies[d] = "*";
162
- const output = deepMerge2({
266
+ const output = deepMerge({
163
267
  file: filename + ".tmp.js",
164
268
  format: "cjs",
165
269
  exports: "auto"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "0.0.3-beta.37",
3
+ "version": "0.0.3-beta.38",
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.37",
26
- "@faasjs/func": "^0.0.3-beta.37",
27
- "@faasjs/ts-transform": "^0.0.3-beta.37",
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",
28
28
  "js-yaml": "*",
29
29
  "rollup": "*"
30
30
  },