@faasjs/load 0.0.3-beta.9 → 0.0.3-beta.91

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.
@@ -0,0 +1,63 @@
1
+ import { Config as Config$1, Func } from '@faasjs/func';
2
+
3
+ /**
4
+ * 配置类
5
+ */
6
+ declare class Config {
7
+ [key: string]: any;
8
+ readonly root: string;
9
+ readonly filename: string;
10
+ readonly origin: {
11
+ [key: string]: Config$1;
12
+ defaults: Config$1;
13
+ };
14
+ readonly defaults: Config$1;
15
+ /**
16
+ * 创建配置类,并自动读取配置内容
17
+ *
18
+ * @param root {string} 根目录
19
+ * @param filename {filename} 目标文件,用于读取目录层级
20
+ */
21
+ constructor(root: string, filename: string);
22
+ }
23
+ /**
24
+ * 加载配置
25
+ * @param root {string} 根目录
26
+ * @param filename {filename} 目标文件,用于读取目录层级
27
+ */
28
+ declare function loadConfig(root: string, filename: string): Config;
29
+
30
+ /**
31
+ * 加载 ts 文件
32
+ *
33
+ * @param filename {string} 完整源文件路径
34
+ * @param options {object} 配置项
35
+ * @param options.input {object} 读取配置
36
+ * @param options.output {object} 写入配置
37
+ * @param options.tmp {boolean} 是否为临时文件,true 则生成的文件会被删除,默认为 false
38
+ * @param options.modules {object} 生成 modules 的配置
39
+ * @param options.modules.excludes {string[]} modules 中需排除的模块
40
+ */
41
+ declare function loadTs(filename: string, options?: {
42
+ input?: {
43
+ [key: string]: any;
44
+ };
45
+ output?: {
46
+ [key: string]: any;
47
+ };
48
+ tmp?: boolean;
49
+ modules?: {
50
+ excludes?: string[];
51
+ additions?: string[];
52
+ };
53
+ }): Promise<{
54
+ module?: Func;
55
+ dependencies: {
56
+ [key: string]: string;
57
+ };
58
+ modules?: {
59
+ [key: string]: string;
60
+ };
61
+ }>;
62
+
63
+ export { loadConfig, loadTs };
package/dist/index.js CHANGED
@@ -1,57 +1,47 @@
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 {
18
+ /**
19
+ * 创建配置类,并自动读取配置内容
20
+ *
21
+ * @param root {string} 根目录
22
+ * @param filename {filename} 目标文件,用于读取目录层级
23
+ */
34
24
  constructor(root, filename) {
35
25
  this.root = root;
36
- if (!this.root.endsWith(import_path.sep))
37
- this.root += import_path.sep;
26
+ if (!this.root.endsWith(path.sep))
27
+ this.root += path.sep;
38
28
  this.filename = filename;
39
29
  const configs = [];
40
- const paths = [this.root, "."].concat((0, import_path.dirname)(filename.replace(root, "")).split(import_path.sep));
41
- paths.reduce(function(base, path) {
42
- 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);
43
33
  if (root2 === base)
44
34
  return base;
45
- const faas = (0, import_path.join)(root2, "faas.yaml");
46
- if ((0, import_fs.existsSync)(faas))
47
- 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()));
48
38
  return root2;
49
39
  });
50
- this.origin = (0, import_deep_merge.deepMerge)(...configs);
51
- 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 || {});
52
42
  for (const key in this.origin) {
53
43
  if (key !== "defaults")
54
- 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]);
55
45
  const data = this[key];
56
46
  if (data.plugins)
57
47
  for (const pluginKey in data.plugins) {
@@ -63,7 +53,7 @@ var Config = class {
63
53
  throw Error(`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`);
64
54
  plugin.provider = data.providers[plugin.provider];
65
55
  } else
66
- 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);
67
57
  }
68
58
  }
69
59
  }
@@ -71,13 +61,6 @@ var Config = class {
71
61
  function loadConfig(root, filename) {
72
62
  return new Config(root, filename);
73
63
  }
74
-
75
- // src/load_ts.ts
76
- var import_deep_merge2 = require("@faasjs/deep_merge");
77
- var import_fs2 = require("fs");
78
- var import_rollup = require("rollup/dist/rollup.js");
79
- var import_path2 = require("path");
80
- var import_ts_transform = require("@faasjs/ts-transform");
81
64
  var FaasPackages = [
82
65
  "@faasjs/cloud_function",
83
66
  "@faasjs/deep_merge",
@@ -94,15 +77,15 @@ var FaasPackages = [
94
77
  "@faasjs/ts-transform"
95
78
  ];
96
79
  function resolveModuleBasePath(moduleName) {
97
- const moduleMainFilePath = require.resolve(moduleName);
80
+ const moduleMainFilePath = __require.resolve(moduleName);
98
81
  const moduleNameParts = moduleName.split("/");
99
82
  let searchForPathSection;
100
83
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
101
84
  const [org, mod] = moduleNameParts;
102
- searchForPathSection = `node_modules${import_path2.sep}${org}${import_path2.sep}${mod}`;
85
+ searchForPathSection = `node_modules${path.sep}${org}${path.sep}${mod}`;
103
86
  } else {
104
87
  const [mod] = moduleNameParts;
105
- searchForPathSection = `node_modules${import_path2.sep}${mod}`;
88
+ searchForPathSection = `node_modules${path.sep}${mod}`;
106
89
  }
107
90
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
108
91
  if (lastIndex === -1) {
@@ -117,7 +100,7 @@ function findModule(list, key, options = { excludes: [] }) {
117
100
  if (key.startsWith("@types/") || options.excludes.includes(key))
118
101
  return;
119
102
  try {
120
- 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")));
121
104
  } catch (error) {
122
105
  console.warn(error);
123
106
  try {
@@ -128,7 +111,7 @@ function findModule(list, key, options = { excludes: [] }) {
128
111
  }
129
112
  if (!list[key])
130
113
  return;
131
- 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());
132
115
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
133
116
  if (pkg.peerDependenciesMeta) {
134
117
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -145,7 +128,7 @@ function swc(externalModules) {
145
128
  return {
146
129
  name: "swc",
147
130
  async transform(code, filename) {
148
- return (0, import_ts_transform.bundle)({
131
+ return tsTransform.bundle({
149
132
  filename,
150
133
  externalModules
151
134
  });
@@ -154,23 +137,23 @@ function swc(externalModules) {
154
137
  }
155
138
  async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
156
139
  var _a;
157
- const PackageJSON = require(`${process.cwd()}/package.json`);
140
+ const PackageJSON = __require(`${process.cwd()}/package.json`);
158
141
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
159
142
  if (options.modules && options.modules.excludes == null)
160
143
  options.modules.excludes = [];
161
- const input = (0, import_deep_merge2.deepMerge)({
144
+ const input = deep_merge.deepMerge({
162
145
  input: filename,
163
146
  external,
164
147
  plugins: [swc(external.concat(FaasPackages))],
165
148
  onwarn: () => null
166
149
  }, options.input || {});
167
- const bundle2 = await (0, import_rollup.rollup)(input);
150
+ const bundle2 = await rollup_js.rollup(input);
168
151
  const dependencies = /* @__PURE__ */ Object.create(null);
169
152
  for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
170
153
  for (const d of m.dependencies)
171
- if (!d.startsWith("/") && !dependencies[d] && !import_ts_transform.NodeBuiltinModules.includes(d))
154
+ if (!d.startsWith("/") && !dependencies[d] && !tsTransform.NodeBuiltinModules.includes(d))
172
155
  dependencies[d] = "*";
173
- const output = (0, import_deep_merge2.deepMerge)({
156
+ const output = deep_merge.deepMerge({
174
157
  file: filename + ".tmp.js",
175
158
  format: "cjs",
176
159
  exports: "auto"
@@ -178,9 +161,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
178
161
  await bundle2.write(output);
179
162
  const result = /* @__PURE__ */ Object.create(null);
180
163
  result.dependencies = dependencies;
181
- result.module = require(output.file);
164
+ result.module = __require(output.file);
182
165
  if (options.tmp)
183
- (0, import_fs2.unlinkSync)(output.file);
166
+ fs.unlinkSync(output.file);
184
167
  if (options.modules) {
185
168
  const modules = /* @__PURE__ */ Object.create(null);
186
169
  Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
@@ -190,8 +173,6 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
190
173
  }
191
174
  return result;
192
175
  }
193
- // Annotate the CommonJS export names for ESM import in node:
194
- 0 && (module.exports = {
195
- loadConfig,
196
- loadTs
197
- });
176
+
177
+ exports.loadConfig = loadConfig;
178
+ exports.loadTs = loadTs;
package/dist/index.mjs CHANGED
@@ -1,21 +1,24 @@
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) {
4
11
  if (typeof require !== "undefined")
5
12
  return require.apply(this, arguments);
6
- throw new Error('Dynamic require of "' + x + '" is not supported');
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 {
16
+ /**
17
+ * 创建配置类,并自动读取配置内容
18
+ *
19
+ * @param root {string} 根目录
20
+ * @param filename {filename} 目标文件,用于读取目录层级
21
+ */
19
22
  constructor(root, filename) {
20
23
  this.root = root;
21
24
  if (!this.root.endsWith(sep))
@@ -56,17 +59,6 @@ var Config = class {
56
59
  function loadConfig(root, filename) {
57
60
  return new Config(root, filename);
58
61
  }
59
-
60
- // src/load_ts.ts
61
- import { deepMerge as deepMerge2 } from "@faasjs/deep_merge";
62
- import { readFileSync as readFileSync2, unlinkSync } from "fs";
63
- import { rollup } from "rollup/dist/rollup.js";
64
- import {
65
- join as join2,
66
- sep as sep2,
67
- dirname as dirname2
68
- } from "path";
69
- import { bundle, NodeBuiltinModules } from "@faasjs/ts-transform";
70
62
  var FaasPackages = [
71
63
  "@faasjs/cloud_function",
72
64
  "@faasjs/deep_merge",
@@ -88,10 +80,10 @@ function resolveModuleBasePath(moduleName) {
88
80
  let searchForPathSection;
89
81
  if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
90
82
  const [org, mod] = moduleNameParts;
91
- searchForPathSection = `node_modules${sep2}${org}${sep2}${mod}`;
83
+ searchForPathSection = `node_modules${sep}${org}${sep}${mod}`;
92
84
  } else {
93
85
  const [mod] = moduleNameParts;
94
- searchForPathSection = `node_modules${sep2}${mod}`;
86
+ searchForPathSection = `node_modules${sep}${mod}`;
95
87
  }
96
88
  const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
97
89
  if (lastIndex === -1) {
@@ -106,7 +98,7 @@ function findModule(list, key, options = { excludes: [] }) {
106
98
  if (key.startsWith("@types/") || options.excludes.includes(key))
107
99
  return;
108
100
  try {
109
- list[key] = dirname2(__require.resolve(join2(key, "package.json")));
101
+ list[key] = dirname(__require.resolve(join(key, "package.json")));
110
102
  } catch (error) {
111
103
  console.warn(error);
112
104
  try {
@@ -117,7 +109,7 @@ function findModule(list, key, options = { excludes: [] }) {
117
109
  }
118
110
  if (!list[key])
119
111
  return;
120
- const pkg = JSON.parse(readFileSync2(join2(list[key], "package.json")).toString());
112
+ const pkg = JSON.parse(readFileSync(join(list[key], "package.json")).toString());
121
113
  const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
122
114
  if (pkg.peerDependenciesMeta) {
123
115
  Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
@@ -147,7 +139,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
147
139
  const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
148
140
  if (options.modules && options.modules.excludes == null)
149
141
  options.modules.excludes = [];
150
- const input = deepMerge2({
142
+ const input = deepMerge({
151
143
  input: filename,
152
144
  external,
153
145
  plugins: [swc(external.concat(FaasPackages))],
@@ -159,7 +151,7 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
159
151
  for (const d of m.dependencies)
160
152
  if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
161
153
  dependencies[d] = "*";
162
- const output = deepMerge2({
154
+ const output = deepMerge({
163
155
  file: filename + ".tmp.js",
164
156
  format: "cjs",
165
157
  exports: "auto"
@@ -179,7 +171,5 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
179
171
  }
180
172
  return result;
181
173
  }
182
- export {
183
- loadConfig,
184
- loadTs
185
- };
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.9",
3
+ "version": "0.0.3-beta.91",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,16 +15,15 @@
15
15
  },
16
16
  "funding": "https://github.com/sponsors/faasjs",
17
17
  "scripts": {
18
- "build": "tsup-node src/index.ts --format esm,cjs",
19
- "build:types": "tsup-node src/index.ts --dts-only"
18
+ "build": "tsup-node src/index.ts --config ../../tsup.config.json"
20
19
  },
21
20
  "files": [
22
21
  "dist"
23
22
  ],
24
23
  "dependencies": {
25
- "@faasjs/deep_merge": "^0.0.3-beta.9",
26
- "@faasjs/func": "^0.0.3-beta.9",
27
- "@faasjs/ts-transform": "^0.0.3-beta.9",
24
+ "@faasjs/deep_merge": "^0.0.3-beta.91",
25
+ "@faasjs/func": "^0.0.3-beta.91",
26
+ "@faasjs/ts-transform": "^0.0.3-beta.91",
28
27
  "js-yaml": "*",
29
28
  "rollup": "*"
30
29
  },