@faasjs/load 4.2.3 → 4.2.5

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/README.md CHANGED
@@ -14,4 +14,3 @@ npm install @faasjs/load
14
14
  ## Functions
15
15
 
16
16
  - [loadConfig](functions/loadConfig.md)
17
- - [loadTs](functions/loadTs.md)
package/dist/index.d.mts CHANGED
@@ -1,43 +1,8 @@
1
- import { Config, Func } from '@faasjs/func';
1
+ import { Config } from '@faasjs/func';
2
2
 
3
3
  /**
4
4
  * Load configuration from faas.yaml
5
5
  */
6
6
  declare function loadConfig(root: string, filename: string, staging: string): Config;
7
7
 
8
- /**
9
- * 加载 ts 文件
10
- *
11
- * @param filename {string} 完整源文件路径
12
- * @param options {object} 配置项
13
- * @param options.input {object} 读取配置
14
- * @param options.output {object} 写入配置
15
- * @param options.tmp {boolean} 是否为临时文件,true 则生成的文件会被删除,默认为 false
16
- * @param options.modules {object} 生成 modules 的配置
17
- * @param options.modules.excludes {string[]} modules 中需排除的模块
18
- *
19
- * @deprecated
20
- */
21
- declare function loadTs(filename: string, options?: {
22
- input?: {
23
- [key: string]: any;
24
- };
25
- output?: {
26
- [key: string]: any;
27
- };
28
- tmp?: boolean;
29
- modules?: {
30
- excludes?: string[];
31
- additions?: string[];
32
- };
33
- }): Promise<{
34
- module?: Func;
35
- dependencies: {
36
- [key: string]: string;
37
- };
38
- modules?: {
39
- [key: string]: string;
40
- };
41
- }>;
42
-
43
- export { loadConfig, loadTs };
8
+ export { loadConfig };
package/dist/index.d.ts CHANGED
@@ -1,43 +1,8 @@
1
- import { Config, Func } from '@faasjs/func';
1
+ import { Config } from '@faasjs/func';
2
2
 
3
3
  /**
4
4
  * Load configuration from faas.yaml
5
5
  */
6
6
  declare function loadConfig(root: string, filename: string, staging: string): Config;
7
7
 
8
- /**
9
- * 加载 ts 文件
10
- *
11
- * @param filename {string} 完整源文件路径
12
- * @param options {object} 配置项
13
- * @param options.input {object} 读取配置
14
- * @param options.output {object} 写入配置
15
- * @param options.tmp {boolean} 是否为临时文件,true 则生成的文件会被删除,默认为 false
16
- * @param options.modules {object} 生成 modules 的配置
17
- * @param options.modules.excludes {string[]} modules 中需排除的模块
18
- *
19
- * @deprecated
20
- */
21
- declare function loadTs(filename: string, options?: {
22
- input?: {
23
- [key: string]: any;
24
- };
25
- output?: {
26
- [key: string]: any;
27
- };
28
- tmp?: boolean;
29
- modules?: {
30
- excludes?: string[];
31
- additions?: string[];
32
- };
33
- }): Promise<{
34
- module?: Func;
35
- dependencies: {
36
- [key: string]: string;
37
- };
38
- modules?: {
39
- [key: string]: string;
40
- };
41
- }>;
42
-
43
- export { loadConfig, loadTs };
8
+ export { loadConfig };
package/dist/index.js CHANGED
@@ -5,15 +5,8 @@ var path = require('path');
5
5
  var deep_merge = require('@faasjs/deep_merge');
6
6
  var logger = require('@faasjs/logger');
7
7
  var jsYaml = require('js-yaml');
8
- var tsTransform = require('@faasjs/ts-transform');
9
- var rollup_js = require('rollup/dist/rollup.js');
10
8
 
11
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
- }) : x)(function(x) {
14
- if (typeof require !== "undefined") return require.apply(this, arguments);
15
- throw Error('Dynamic require of "' + x + '" is not supported');
16
- });
9
+ // src/load_config.ts
17
10
  var Config = class {
18
11
  root;
19
12
  filename;
@@ -60,125 +53,5 @@ var Config = class {
60
53
  function loadConfig(root, filename, staging) {
61
54
  return new Config(root, filename).get(staging);
62
55
  }
63
- var FaasPackages = [
64
- "@faasjs/cloud_function",
65
- "@faasjs/deep_merge",
66
- "@faasjs/func",
67
- "@faasjs/http",
68
- "@faasjs/knex",
69
- "@faasjs/load",
70
- "@faasjs/logger",
71
- "@faasjs/mongo",
72
- "@faasjs/redis",
73
- "@faasjs/request",
74
- "@faasjs/ts-transform"
75
- ];
76
- function resolveModuleBasePath(moduleName) {
77
- const moduleMainFilePath = __require.resolve(moduleName);
78
- const moduleNameParts = moduleName.split("/");
79
- let searchForPathSection;
80
- if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
81
- const [org, mod] = moduleNameParts;
82
- searchForPathSection = `node_modules${path.sep}${org}${path.sep}${mod}`;
83
- } else {
84
- const [mod] = moduleNameParts;
85
- searchForPathSection = `node_modules${path.sep}${mod}`;
86
- }
87
- const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
88
- if (lastIndex === -1) {
89
- console.log(searchForPathSection, moduleMainFilePath);
90
- throw new Error(
91
- `Couldn't resolve the base path of "${moduleName}". Searched inside the resolved main file path "${moduleMainFilePath}" using "${searchForPathSection}"`
92
- );
93
- }
94
- return moduleMainFilePath.slice(0, lastIndex + searchForPathSection.length);
95
- }
96
- function findModule(list, key, options = { excludes: [] }) {
97
- if (list[key]) return;
98
- if (key.startsWith("@types/") || options.excludes.includes(key)) return;
99
- try {
100
- list[key] = path.dirname(__require.resolve(path.join(key, "package.json")));
101
- } catch (error) {
102
- console.warn(error);
103
- try {
104
- list[key] = resolveModuleBasePath(key);
105
- } catch (error2) {
106
- console.warn(error2);
107
- }
108
- }
109
- if (!list[key]) return;
110
- const pkg = JSON.parse(
111
- fs.readFileSync(path.join(list[key], "package.json")).toString()
112
- );
113
- const deps = Object.keys(pkg.dependencies || {}).concat(
114
- Object.keys(pkg.peerDependencies || {})
115
- );
116
- if (pkg.peerDependenciesMeta) {
117
- for (const key2 of Object.keys(pkg.peerDependenciesMeta)) {
118
- if (pkg.peerDependenciesMeta[key2].optional) {
119
- const index = deps.indexOf(key2);
120
- if (index >= 0) deps.splice(index, 1);
121
- }
122
- }
123
- }
124
- deps.map((d) => findModule(list, d, options));
125
- }
126
- function swc(externalModules) {
127
- return {
128
- name: "swc",
129
- async transform(_, filename) {
130
- return tsTransform.bundle({
131
- filename,
132
- externalModules
133
- });
134
- }
135
- };
136
- }
137
- async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
138
- console.warn("[@faasjs/load] Will deprecated in v3.");
139
- const PackageJSON = __require(`${process.cwd()}/package.json`);
140
- const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
141
- if (options.modules && options.modules.excludes == null)
142
- options.modules.excludes = [];
143
- const input = deep_merge.deepMerge(
144
- {
145
- input: filename,
146
- external,
147
- plugins: [swc(external.concat(FaasPackages))],
148
- onwarn: () => null
149
- },
150
- options.input || {}
151
- );
152
- const bundle2 = await rollup_js.rollup(input);
153
- const dependencies = /* @__PURE__ */ Object.create(null);
154
- for (const m of bundle2.cache?.modules || [])
155
- for (const d of m.dependencies)
156
- if (!d.startsWith("/") && !dependencies[d] && !tsTransform.NodeBuiltinModules.includes(d))
157
- dependencies[d] = "*";
158
- const output = deep_merge.deepMerge(
159
- {
160
- file: `${filename}.tmp.js`,
161
- format: "cjs",
162
- exports: "auto"
163
- },
164
- options.output || {}
165
- );
166
- await bundle2.write(output);
167
- const result = /* @__PURE__ */ Object.create(null);
168
- result.dependencies = dependencies;
169
- result.module = __require(output.file);
170
- if (options.tmp) fs.unlinkSync(output.file);
171
- if (options.modules) {
172
- const modules = /* @__PURE__ */ Object.create(null);
173
- Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
174
- if (options.modules.additions)
175
- options.modules.additions.map(
176
- (d) => findModule(modules, d, options.modules)
177
- );
178
- result.modules = modules;
179
- }
180
- return result;
181
- }
182
56
 
183
57
  exports.loadConfig = loadConfig;
184
- exports.loadTs = loadTs;
package/dist/index.mjs CHANGED
@@ -1,17 +1,10 @@
1
- import { unlinkSync, existsSync, readFileSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { sep, dirname, join } from 'node:path';
3
3
  import { deepMerge } from '@faasjs/deep_merge';
4
4
  import { Logger } from '@faasjs/logger';
5
5
  import { load } from 'js-yaml';
6
- import { NodeBuiltinModules, bundle } from '@faasjs/ts-transform';
7
- import { rollup } from 'rollup/dist/rollup.js';
8
6
 
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
7
+ // src/load_config.ts
15
8
  var Config = class {
16
9
  root;
17
10
  filename;
@@ -58,124 +51,5 @@ var Config = class {
58
51
  function loadConfig(root, filename, staging) {
59
52
  return new Config(root, filename).get(staging);
60
53
  }
61
- var FaasPackages = [
62
- "@faasjs/cloud_function",
63
- "@faasjs/deep_merge",
64
- "@faasjs/func",
65
- "@faasjs/http",
66
- "@faasjs/knex",
67
- "@faasjs/load",
68
- "@faasjs/logger",
69
- "@faasjs/mongo",
70
- "@faasjs/redis",
71
- "@faasjs/request",
72
- "@faasjs/ts-transform"
73
- ];
74
- function resolveModuleBasePath(moduleName) {
75
- const moduleMainFilePath = __require.resolve(moduleName);
76
- const moduleNameParts = moduleName.split("/");
77
- let searchForPathSection;
78
- if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
79
- const [org, mod] = moduleNameParts;
80
- searchForPathSection = `node_modules${sep}${org}${sep}${mod}`;
81
- } else {
82
- const [mod] = moduleNameParts;
83
- searchForPathSection = `node_modules${sep}${mod}`;
84
- }
85
- const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
86
- if (lastIndex === -1) {
87
- console.log(searchForPathSection, moduleMainFilePath);
88
- throw new Error(
89
- `Couldn't resolve the base path of "${moduleName}". Searched inside the resolved main file path "${moduleMainFilePath}" using "${searchForPathSection}"`
90
- );
91
- }
92
- return moduleMainFilePath.slice(0, lastIndex + searchForPathSection.length);
93
- }
94
- function findModule(list, key, options = { excludes: [] }) {
95
- if (list[key]) return;
96
- if (key.startsWith("@types/") || options.excludes.includes(key)) return;
97
- try {
98
- list[key] = dirname(__require.resolve(join(key, "package.json")));
99
- } catch (error) {
100
- console.warn(error);
101
- try {
102
- list[key] = resolveModuleBasePath(key);
103
- } catch (error2) {
104
- console.warn(error2);
105
- }
106
- }
107
- if (!list[key]) return;
108
- const pkg = JSON.parse(
109
- readFileSync(join(list[key], "package.json")).toString()
110
- );
111
- const deps = Object.keys(pkg.dependencies || {}).concat(
112
- Object.keys(pkg.peerDependencies || {})
113
- );
114
- if (pkg.peerDependenciesMeta) {
115
- for (const key2 of Object.keys(pkg.peerDependenciesMeta)) {
116
- if (pkg.peerDependenciesMeta[key2].optional) {
117
- const index = deps.indexOf(key2);
118
- if (index >= 0) deps.splice(index, 1);
119
- }
120
- }
121
- }
122
- deps.map((d) => findModule(list, d, options));
123
- }
124
- function swc(externalModules) {
125
- return {
126
- name: "swc",
127
- async transform(_, filename) {
128
- return bundle({
129
- filename,
130
- externalModules
131
- });
132
- }
133
- };
134
- }
135
- async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
136
- console.warn("[@faasjs/load] Will deprecated in v3.");
137
- const PackageJSON = __require(`${process.cwd()}/package.json`);
138
- const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
139
- if (options.modules && options.modules.excludes == null)
140
- options.modules.excludes = [];
141
- const input = deepMerge(
142
- {
143
- input: filename,
144
- external,
145
- plugins: [swc(external.concat(FaasPackages))],
146
- onwarn: () => null
147
- },
148
- options.input || {}
149
- );
150
- const bundle2 = await rollup(input);
151
- const dependencies = /* @__PURE__ */ Object.create(null);
152
- for (const m of bundle2.cache?.modules || [])
153
- for (const d of m.dependencies)
154
- if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
155
- dependencies[d] = "*";
156
- const output = deepMerge(
157
- {
158
- file: `${filename}.tmp.js`,
159
- format: "cjs",
160
- exports: "auto"
161
- },
162
- options.output || {}
163
- );
164
- await bundle2.write(output);
165
- const result = /* @__PURE__ */ Object.create(null);
166
- result.dependencies = dependencies;
167
- result.module = __require(output.file);
168
- if (options.tmp) unlinkSync(output.file);
169
- if (options.modules) {
170
- const modules = /* @__PURE__ */ Object.create(null);
171
- Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
172
- if (options.modules.additions)
173
- options.modules.additions.map(
174
- (d) => findModule(modules, d, options.modules)
175
- );
176
- result.modules = modules;
177
- }
178
- return result;
179
- }
180
54
 
181
- export { loadConfig, loadTs };
55
+ export { loadConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "4.2.3",
3
+ "version": "4.2.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -35,18 +35,14 @@
35
35
  ],
36
36
  "peerDependencies": {
37
37
  "js-yaml": "*",
38
- "rollup": "*",
39
- "@faasjs/deep_merge": "4.2.3",
40
- "@faasjs/func": "4.2.3",
41
- "@faasjs/ts-transform": "4.2.3"
38
+ "@faasjs/deep_merge": "4.2.5",
39
+ "@faasjs/func": "4.2.5"
42
40
  },
43
41
  "devDependencies": {
44
42
  "js-yaml": "*",
45
- "rollup": "*",
46
43
  "@types/js-yaml": "*",
47
- "@faasjs/deep_merge": "4.2.3",
48
- "@faasjs/func": "4.2.3",
49
- "@faasjs/ts-transform": "4.2.3"
44
+ "@faasjs/deep_merge": "4.2.5",
45
+ "@faasjs/func": "4.2.5"
50
46
  },
51
47
  "engines": {
52
48
  "node": ">=22.0.0",