@faasjs/load 0.0.3-beta.99 → 0.0.4-beta.2
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 +42 -19
- package/dist/index.mjs +42 -19
- package/package.json +13 -8
package/dist/index.js
CHANGED
|
@@ -27,14 +27,18 @@ var Config = class {
|
|
|
27
27
|
this.root += path.sep;
|
|
28
28
|
this.filename = filename;
|
|
29
29
|
const configs = [];
|
|
30
|
-
const paths = [this.root, "."].concat(
|
|
30
|
+
const paths = [this.root, "."].concat(
|
|
31
|
+
path.dirname(filename.replace(root, "")).split(path.sep)
|
|
32
|
+
);
|
|
31
33
|
paths.reduce(function(base, path$1) {
|
|
32
34
|
const root2 = path.join(base, path$1);
|
|
33
35
|
if (root2 === base)
|
|
34
36
|
return base;
|
|
35
37
|
const faas = path.join(root2, "faas.yaml");
|
|
36
38
|
if (fs.existsSync(faas))
|
|
37
|
-
configs.push(
|
|
39
|
+
configs.push(
|
|
40
|
+
jsYaml.load(fs.readFileSync(faas).toString())
|
|
41
|
+
);
|
|
38
42
|
return root2;
|
|
39
43
|
});
|
|
40
44
|
this.origin = deep_merge.deepMerge(...configs);
|
|
@@ -50,10 +54,15 @@ var Config = class {
|
|
|
50
54
|
if (plugin.provider)
|
|
51
55
|
if (typeof plugin.provider === "string") {
|
|
52
56
|
if (!data.providers[plugin.provider])
|
|
53
|
-
throw Error(
|
|
57
|
+
throw Error(
|
|
58
|
+
`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`
|
|
59
|
+
);
|
|
54
60
|
plugin.provider = data.providers[plugin.provider];
|
|
55
61
|
} else
|
|
56
|
-
plugin.provider = deep_merge.deepMerge(
|
|
62
|
+
plugin.provider = deep_merge.deepMerge(
|
|
63
|
+
data.providers[plugin.provider],
|
|
64
|
+
plugin.provider
|
|
65
|
+
);
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
}
|
|
@@ -90,7 +99,9 @@ function resolveModuleBasePath(moduleName) {
|
|
|
90
99
|
const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
|
|
91
100
|
if (lastIndex === -1) {
|
|
92
101
|
console.log(searchForPathSection, moduleMainFilePath);
|
|
93
|
-
throw new Error(
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Couldn't resolve the base path of "${moduleName}". Searched inside the resolved main file path "${moduleMainFilePath}" using "${searchForPathSection}"`
|
|
104
|
+
);
|
|
94
105
|
}
|
|
95
106
|
return moduleMainFilePath.slice(0, lastIndex + searchForPathSection.length);
|
|
96
107
|
}
|
|
@@ -111,8 +122,12 @@ function findModule(list, key, options = { excludes: [] }) {
|
|
|
111
122
|
}
|
|
112
123
|
if (!list[key])
|
|
113
124
|
return;
|
|
114
|
-
const pkg = JSON.parse(
|
|
115
|
-
|
|
125
|
+
const pkg = JSON.parse(
|
|
126
|
+
fs.readFileSync(path.join(list[key], "package.json")).toString()
|
|
127
|
+
);
|
|
128
|
+
const deps = Object.keys(pkg.dependencies || {}).concat(
|
|
129
|
+
Object.keys(pkg.peerDependencies || {})
|
|
130
|
+
);
|
|
116
131
|
if (pkg.peerDependenciesMeta) {
|
|
117
132
|
Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
|
|
118
133
|
if (pkg.peerDependenciesMeta[key2].optional) {
|
|
@@ -141,23 +156,29 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
|
|
|
141
156
|
const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
|
|
142
157
|
if (options.modules && options.modules.excludes == null)
|
|
143
158
|
options.modules.excludes = [];
|
|
144
|
-
const input = deep_merge.deepMerge(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
const input = deep_merge.deepMerge(
|
|
160
|
+
{
|
|
161
|
+
input: filename,
|
|
162
|
+
external,
|
|
163
|
+
plugins: [swc(external.concat(FaasPackages))],
|
|
164
|
+
onwarn: () => null
|
|
165
|
+
},
|
|
166
|
+
options.input || {}
|
|
167
|
+
);
|
|
150
168
|
const bundle2 = await rollup_js.rollup(input);
|
|
151
169
|
const dependencies = /* @__PURE__ */ Object.create(null);
|
|
152
170
|
for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
|
|
153
171
|
for (const d of m.dependencies)
|
|
154
172
|
if (!d.startsWith("/") && !dependencies[d] && !tsTransform.NodeBuiltinModules.includes(d))
|
|
155
173
|
dependencies[d] = "*";
|
|
156
|
-
const output = deep_merge.deepMerge(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
174
|
+
const output = deep_merge.deepMerge(
|
|
175
|
+
{
|
|
176
|
+
file: `${filename}.tmp.js`,
|
|
177
|
+
format: "cjs",
|
|
178
|
+
exports: "auto"
|
|
179
|
+
},
|
|
180
|
+
options.output || {}
|
|
181
|
+
);
|
|
161
182
|
await bundle2.write(output);
|
|
162
183
|
const result = /* @__PURE__ */ Object.create(null);
|
|
163
184
|
result.dependencies = dependencies;
|
|
@@ -168,7 +189,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
|
|
|
168
189
|
const modules = /* @__PURE__ */ Object.create(null);
|
|
169
190
|
Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
|
|
170
191
|
if (options.modules.additions)
|
|
171
|
-
options.modules.additions.map(
|
|
192
|
+
options.modules.additions.map(
|
|
193
|
+
(d) => findModule(modules, d, options.modules)
|
|
194
|
+
);
|
|
172
195
|
result.modules = modules;
|
|
173
196
|
}
|
|
174
197
|
return result;
|
package/dist/index.mjs
CHANGED
|
@@ -25,14 +25,18 @@ var Config = class {
|
|
|
25
25
|
this.root += sep;
|
|
26
26
|
this.filename = filename;
|
|
27
27
|
const configs = [];
|
|
28
|
-
const paths = [this.root, "."].concat(
|
|
28
|
+
const paths = [this.root, "."].concat(
|
|
29
|
+
dirname(filename.replace(root, "")).split(sep)
|
|
30
|
+
);
|
|
29
31
|
paths.reduce(function(base, path) {
|
|
30
32
|
const root2 = join(base, path);
|
|
31
33
|
if (root2 === base)
|
|
32
34
|
return base;
|
|
33
35
|
const faas = join(root2, "faas.yaml");
|
|
34
36
|
if (existsSync(faas))
|
|
35
|
-
configs.push(
|
|
37
|
+
configs.push(
|
|
38
|
+
load(readFileSync(faas).toString())
|
|
39
|
+
);
|
|
36
40
|
return root2;
|
|
37
41
|
});
|
|
38
42
|
this.origin = deepMerge(...configs);
|
|
@@ -48,10 +52,15 @@ var Config = class {
|
|
|
48
52
|
if (plugin.provider)
|
|
49
53
|
if (typeof plugin.provider === "string") {
|
|
50
54
|
if (!data.providers[plugin.provider])
|
|
51
|
-
throw Error(
|
|
55
|
+
throw Error(
|
|
56
|
+
`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`
|
|
57
|
+
);
|
|
52
58
|
plugin.provider = data.providers[plugin.provider];
|
|
53
59
|
} else
|
|
54
|
-
plugin.provider = deepMerge(
|
|
60
|
+
plugin.provider = deepMerge(
|
|
61
|
+
data.providers[plugin.provider],
|
|
62
|
+
plugin.provider
|
|
63
|
+
);
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
}
|
|
@@ -88,7 +97,9 @@ function resolveModuleBasePath(moduleName) {
|
|
|
88
97
|
const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
|
|
89
98
|
if (lastIndex === -1) {
|
|
90
99
|
console.log(searchForPathSection, moduleMainFilePath);
|
|
91
|
-
throw new Error(
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Couldn't resolve the base path of "${moduleName}". Searched inside the resolved main file path "${moduleMainFilePath}" using "${searchForPathSection}"`
|
|
102
|
+
);
|
|
92
103
|
}
|
|
93
104
|
return moduleMainFilePath.slice(0, lastIndex + searchForPathSection.length);
|
|
94
105
|
}
|
|
@@ -109,8 +120,12 @@ function findModule(list, key, options = { excludes: [] }) {
|
|
|
109
120
|
}
|
|
110
121
|
if (!list[key])
|
|
111
122
|
return;
|
|
112
|
-
const pkg = JSON.parse(
|
|
113
|
-
|
|
123
|
+
const pkg = JSON.parse(
|
|
124
|
+
readFileSync(join(list[key], "package.json")).toString()
|
|
125
|
+
);
|
|
126
|
+
const deps = Object.keys(pkg.dependencies || {}).concat(
|
|
127
|
+
Object.keys(pkg.peerDependencies || {})
|
|
128
|
+
);
|
|
114
129
|
if (pkg.peerDependenciesMeta) {
|
|
115
130
|
Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
|
|
116
131
|
if (pkg.peerDependenciesMeta[key2].optional) {
|
|
@@ -139,23 +154,29 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
|
|
|
139
154
|
const external = PackageJSON.dependencies ? Object.keys(PackageJSON.dependencies) : [];
|
|
140
155
|
if (options.modules && options.modules.excludes == null)
|
|
141
156
|
options.modules.excludes = [];
|
|
142
|
-
const input = deepMerge(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
const input = deepMerge(
|
|
158
|
+
{
|
|
159
|
+
input: filename,
|
|
160
|
+
external,
|
|
161
|
+
plugins: [swc(external.concat(FaasPackages))],
|
|
162
|
+
onwarn: () => null
|
|
163
|
+
},
|
|
164
|
+
options.input || {}
|
|
165
|
+
);
|
|
148
166
|
const bundle2 = await rollup(input);
|
|
149
167
|
const dependencies = /* @__PURE__ */ Object.create(null);
|
|
150
168
|
for (const m of ((_a = bundle2.cache) == null ? void 0 : _a.modules) || [])
|
|
151
169
|
for (const d of m.dependencies)
|
|
152
170
|
if (!d.startsWith("/") && !dependencies[d] && !NodeBuiltinModules.includes(d))
|
|
153
171
|
dependencies[d] = "*";
|
|
154
|
-
const output = deepMerge(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
const output = deepMerge(
|
|
173
|
+
{
|
|
174
|
+
file: `${filename}.tmp.js`,
|
|
175
|
+
format: "cjs",
|
|
176
|
+
exports: "auto"
|
|
177
|
+
},
|
|
178
|
+
options.output || {}
|
|
179
|
+
);
|
|
159
180
|
await bundle2.write(output);
|
|
160
181
|
const result = /* @__PURE__ */ Object.create(null);
|
|
161
182
|
result.dependencies = dependencies;
|
|
@@ -166,7 +187,9 @@ async function loadTs(filename, options = /* @__PURE__ */ Object.create(null)) {
|
|
|
166
187
|
const modules = /* @__PURE__ */ Object.create(null);
|
|
167
188
|
Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
|
|
168
189
|
if (options.modules.additions)
|
|
169
|
-
options.modules.additions.map(
|
|
190
|
+
options.modules.additions.map(
|
|
191
|
+
(d) => findModule(modules, d, options.modules)
|
|
192
|
+
);
|
|
170
193
|
result.modules = modules;
|
|
171
194
|
}
|
|
172
195
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/load",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,18 +20,23 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
|
-
"
|
|
24
|
-
"@faasjs/deep_merge": "0.0.
|
|
25
|
-
"@faasjs/func": "0.0.
|
|
26
|
-
"@faasjs/ts-transform": "0.0.
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@faasjs/deep_merge": "0.0.4-beta.2",
|
|
25
|
+
"@faasjs/func": "0.0.4-beta.2",
|
|
26
|
+
"@faasjs/ts-transform": "0.0.4-beta.2",
|
|
27
27
|
"js-yaml": "*",
|
|
28
28
|
"rollup": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/js-yaml": "*"
|
|
31
|
+
"@types/js-yaml": "*",
|
|
32
|
+
"@faasjs/deep_merge": "0.0.4-beta.2",
|
|
33
|
+
"@faasjs/func": "0.0.4-beta.2",
|
|
34
|
+
"@faasjs/ts-transform": "0.0.4-beta.2",
|
|
35
|
+
"js-yaml": "*",
|
|
36
|
+
"rollup": "*"
|
|
32
37
|
},
|
|
33
38
|
"engines": {
|
|
34
|
-
"npm": ">=
|
|
35
|
-
"node": ">=
|
|
39
|
+
"npm": ">=9.0.0",
|
|
40
|
+
"node": ">=18.0.0"
|
|
36
41
|
}
|
|
37
42
|
}
|