@faasjs/load 0.0.3-beta.87 → 0.0.3-beta.89

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
@@ -1,35 +1,19 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- loadConfig: () => loadConfig,
24
- loadTs: () => loadTs
25
- });
26
- module.exports = __toCommonJS(src_exports);
3
+ var deep_merge = require('@faasjs/deep_merge');
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+ var jsYaml = require('js-yaml');
7
+ var rollup_js = require('rollup/dist/rollup.js');
8
+ var tsTransform = require('@faasjs/ts-transform');
27
9
 
28
- // src/load_config.ts
29
- var import_deep_merge = require("@faasjs/deep_merge");
30
- var import_fs = require("fs");
31
- var import_path = require("path");
32
- var import_js_yaml = require("js-yaml");
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined")
14
+ return require.apply(this, arguments);
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
+ });
33
17
  var Config = class {
34
18
  /**
35
19
  * 创建配置类,并自动读取配置内容
@@ -39,25 +23,25 @@ var Config = class {
39
23
  */
40
24
  constructor(root, filename) {
41
25
  this.root = root;
42
- if (!this.root.endsWith(import_path.sep))
43
- this.root += import_path.sep;
26
+ if (!this.root.endsWith(path.sep))
27
+ this.root += path.sep;
44
28
  this.filename = filename;
45
29
  const configs = [];
46
- const paths = [this.root, "."].concat((0, import_path.dirname)(filename.replace(root, "")).split(import_path.sep));
47
- paths.reduce(function(base, path) {
48
- const root2 = (0, import_path.join)(base, path);
30
+ const paths = [this.root, "."].concat(path.dirname(filename.replace(root, "")).split(path.sep));
31
+ paths.reduce(function(base, path$1) {
32
+ const root2 = path.join(base, path$1);
49
33
  if (root2 === base)
50
34
  return base;
51
- const faas = (0, import_path.join)(root2, "faas.yaml");
52
- if ((0, import_fs.existsSync)(faas))
53
- configs.push((0, import_js_yaml.load)((0, import_fs.readFileSync)(faas).toString()));
35
+ const faas = path.join(root2, "faas.yaml");
36
+ if (fs.existsSync(faas))
37
+ configs.push(jsYaml.load(fs.readFileSync(faas).toString()));
54
38
  return root2;
55
39
  });
56
- this.origin = (0, import_deep_merge.deepMerge)(...configs);
57
- this.defaults = (0, import_deep_merge.deepMerge)(this.origin.defaults || {});
40
+ this.origin = deep_merge.deepMerge(...configs);
41
+ this.defaults = deep_merge.deepMerge(this.origin.defaults || {});
58
42
  for (const key in this.origin) {
59
43
  if (key !== "defaults")
60
- this[key] = (0, import_deep_merge.deepMerge)(this.origin.defaults, this.origin[key]);
44
+ this[key] = deep_merge.deepMerge(this.origin.defaults, this.origin[key]);
61
45
  const data = this[key];
62
46
  if (data.plugins)
63
47
  for (const pluginKey in data.plugins) {
@@ -69,7 +53,7 @@ var Config = class {
69
53
  throw Error(`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`);
70
54
  plugin.provider = data.providers[plugin.provider];
71
55
  } else
72
- plugin.provider = (0, import_deep_merge.deepMerge)(data.providers[plugin.provider], plugin.provider);
56
+ plugin.provider = deep_merge.deepMerge(data.providers[plugin.provider], plugin.provider);
73
57
  }
74
58
  }
75
59
  }
@@ -77,13 +61,6 @@ var Config = class {
77
61
  function loadConfig(root, filename) {
78
62
  return new Config(root, filename);
79
63
  }
80
-
81
- // src/load_ts.ts
82
- var import_deep_merge2 = require("@faasjs/deep_merge");
83
- var import_fs2 = require("fs");
84
- var import_rollup = require("rollup/dist/rollup.js");
85
- var import_path2 = require("path");
86
- var import_ts_transform = require("@faasjs/ts-transform");
87
64
  var FaasPackages = [
88
65
  "@faasjs/cloud_function",
89
66
  "@faasjs/deep_merge",
@@ -100,15 +77,15 @@ var FaasPackages = [
100
77
  "@faasjs/ts-transform"
101
78
  ];
102
79
  function resolveModuleBasePath(moduleName) {
103
- const moduleMainFilePath = require.resolve(moduleName);
80
+ const moduleMainFilePath = __require.resolve(moduleName);
104
81
  const moduleNameParts = moduleName.split("/");
105
82
  let searchForPathSection;
106
83
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
107
84
  const [org, mod] = moduleNameParts;
108
- searchForPathSection = `node_modules${import_path2.sep}${org}${import_path2.sep}${mod}`;
85
+ searchForPathSection = `node_modules${path.sep}${org}${path.sep}${mod}`;
109
86
  } else {
110
87
  const [mod] = moduleNameParts;
111
- searchForPathSection = `node_modules${import_path2.sep}${mod}`;
88
+ searchForPathSection = `node_modules${path.sep}${mod}`;
112
89
  }
113
90
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
114
91
  if (lastIndex === -1) {
@@ -123,7 +100,7 @@ function findModule(list, key, options = { excludes: [] }) {
123
100
  if (key.startsWith("@types/") || options.excludes.includes(key))
124
101
  return;
125
102
  try {
126
- list[key] = (0, import_path2.dirname)(require.resolve((0, import_path2.join)(key, "package.json")));
103
+ list[key] = path.dirname(__require.resolve(path.join(key, "package.json")));
127
104
  } catch (error) {
128
105
  console.warn(error);
129
106
  try {
@@ -134,7 +111,7 @@ function findModule(list, key, options = { excludes: [] }) {
134
111
  }
135
112
  if (!list[key])
136
113
  return;
137
- const pkg = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(list[key], "package.json")).toString());
114
+ const pkg = JSON.parse(fs.readFileSync(path.join(list[key], "package.json")).toString());
138
115
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
139
116
  if (pkg.peerDependenciesMeta) {
140
117
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -151,7 +128,7 @@ function swc(externalModules) {
151
128
  return {
152
129
  name: "swc",
153
130
  async transform(code, filename) {
154
- return (0, import_ts_transform.bundle)({
131
+ return tsTransform.bundle({
155
132
  filename,
156
133
  externalModules
157
134
  });
@@ -160,23 +137,23 @@ function swc(externalModules) {
160
137
  }
161
138
  async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
162
139
  var _a;
163
- const PackageJSON = require(`${process.cwd()}/package.json`);
140
+ const PackageJSON = __require(`${process.cwd()}/package.json`);
164
141
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
165
142
  if (options.modules && options.modules.excludes == null)
166
143
  options.modules.excludes = [];
167
- const input = (0, import_deep_merge2.deepMerge)({
144
+ const input = deep_merge.deepMerge({
168
145
  input: filename,
169
146
  external,
170
147
  plugins: [swc(external.concat(FaasPackages))],
171
148
  onwarn: () => null
172
149
  }, options.input || {});
173
- const bundle2 = await (0, import_rollup.rollup)(input);
150
+ const bundle2 = await rollup_js.rollup(input);
174
151
  const dependencies = /* @__PURE__ */ Object.create(null);
175
152
  for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
176
153
  for (const d of m.dependencies)
177
- if (!d.startsWith("/") && !dependencies[d] && !import_ts_transform.NodeBuiltinModules.includes(d))
154
+ if (!d.startsWith("/") && !dependencies[d] && !tsTransform.NodeBuiltinModules.includes(d))
178
155
  dependencies[d] = "*";
179
- const output = (0, import_deep_merge2.deepMerge)({
156
+ const output = deep_merge.deepMerge({
180
157
  file: filename + ".tmp.js",
181
158
  format: "cjs",
182
159
  exports: "auto"
@@ -184,9 +161,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
184
161
  await bundle2.write(output);
185
162
  const result = /* @__PURE__ */ Object.create(null);
186
163
  result.dependencies = dependencies;
187
- result.module = require(output.file);
164
+ result.module = __require(output.file);
188
165
  if (options.tmp)
189
- (0, import_fs2.unlinkSync)(output.file);
166
+ fs.unlinkSync(output.file);
190
167
  if (options.modules) {
191
168
  const modules = /* @__PURE__ */ Object.create(null);
192
169
  Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
@@ -196,8 +173,6 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
196
173
  }
197
174
  return result;
198
175
  }
199
- // Annotate the CommonJS export names for ESM import in node:
200
- 0 && (module.exports = {
201
- loadConfig,
202
- loadTs
203
- });
176
+
177
+ exports.loadConfig = loadConfig;
178
+ exports.loadTs = loadTs;
package/dist/index.mjs CHANGED
@@ -1,3 +1,10 @@
1
+ import { deepMerge } from '@faasjs/deep_merge';
2
+ import { unlinkSync, existsSync, readFileSync } from 'fs';
3
+ import { sep, dirname, join } from 'path';
4
+ import { load } from 'js-yaml';
5
+ import { rollup } from 'rollup/dist/rollup.js';
6
+ import { NodeBuiltinModules, bundle } from '@faasjs/ts-transform';
7
+
1
8
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
9
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
10
  }) : x)(function(x) {
@@ -5,16 +12,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
5
12
  return require.apply(this, arguments);
6
13
  throw Error('Dynamic require of "' + x + '" is not supported');
7
14
  });
8
-
9
- // src/load_config.ts
10
- import { deepMerge } from "@faasjs/deep_merge";
11
- import { existsSync, readFileSync } from "fs";
12
- import {
13
- sep,
14
- dirname,
15
- join
16
- } from "path";
17
- import { load } from "js-yaml";
18
15
  var Config = class {
19
16
  /**
20
17
  * 创建配置类,并自动读取配置内容
@@ -62,17 +59,6 @@ var Config = class {
62
59
  function loadConfig(root, filename) {
63
60
  return new Config(root, filename);
64
61
  }
65
-
66
- // src/load_ts.ts
67
- import { deepMerge as deepMerge2 } from "@faasjs/deep_merge";
68
- import { readFileSync as readFileSync2, unlinkSync } from "fs";
69
- import { rollup } from "rollup/dist/rollup.js";
70
- import {
71
- join as join2,
72
- sep as sep2,
73
- dirname as dirname2
74
- } from "path";
75
- import { bundle, NodeBuiltinModules } from "@faasjs/ts-transform";
76
62
  var FaasPackages = [
77
63
  "@faasjs/cloud_function",
78
64
  "@faasjs/deep_merge",
@@ -94,10 +80,10 @@ function resolveModuleBasePath(moduleName) {
94
80
  let searchForPathSection;
95
81
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
96
82
  const [org, mod] = moduleNameParts;
97
- searchForPathSection = `node_modules${sep2}${org}${sep2}${mod}`;
83
+ searchForPathSection = `node_modules${sep}${org}${sep}${mod}`;
98
84
  } else {
99
85
  const [mod] = moduleNameParts;
100
- searchForPathSection = `node_modules${sep2}${mod}`;
86
+ searchForPathSection = `node_modules${sep}${mod}`;
101
87
  }
102
88
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
103
89
  if (lastIndex === -1) {
@@ -112,7 +98,7 @@ function findModule(list, key, options = { excludes: [] }) {
112
98
  if (key.startsWith("@types/") || options.excludes.includes(key))
113
99
  return;
114
100
  try {
115
- list[key] = dirname2(__require.resolve(join2(key, "package.json")));
101
+ list[key] = dirname(__require.resolve(join(key, "package.json")));
116
102
  } catch (error) {
117
103
  console.warn(error);
118
104
  try {
@@ -123,7 +109,7 @@ function findModule(list, key, options = { excludes: [] }) {
123
109
  }
124
110
  if (!list[key])
125
111
  return;
126
- const pkg = JSON.parse(readFileSync2(join2(list[key], "package.json")).toString());
112
+ const pkg = JSON.parse(readFileSync(join(list[key], "package.json")).toString());
127
113
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
128
114
  if (pkg.peerDependenciesMeta) {
129
115
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -153,7 +139,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
153
139
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
154
140
  if (options.modules && options.modules.excludes == null)
155
141
  options.modules.excludes = [];
156
- const input = deepMerge2({
142
+ const input = deepMerge({
157
143
  input: filename,
158
144
  external,
159
145
  plugins: [swc(external.concat(FaasPackages))],
@@ -165,7 +151,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
165
151
  for (const d of m.dependencies)
166
152
  if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
167
153
  dependencies[d] = "*";
168
- const output = deepMerge2({
154
+ const output = deepMerge({
169
155
  file: filename + ".tmp.js",
170
156
  format: "cjs",
171
157
  exports: "auto"
@@ -185,7 +171,5 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
185
171
  }
186
172
  return result;
187
173
  }
188
- export {
189
- loadConfig,
190
- loadTs
191
- };
174
+
175
+ export { loadConfig, loadTs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "0.0.3-beta.87",
3
+ "version": "0.0.3-beta.89",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,9 +21,9 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "@faasjs/deep_merge": "^0.0.3-beta.87",
25
- "@faasjs/func": "^0.0.3-beta.87",
26
- "@faasjs/ts-transform": "^0.0.3-beta.87",
24
+ "@faasjs/deep_merge": "^0.0.3-beta.89",
25
+ "@faasjs/func": "^0.0.3-beta.89",
26
+ "@faasjs/ts-transform": "^0.0.3-beta.89",
27
27
  "js-yaml": "*",
28
28
  "rollup": "*"
29
29
  },