@faasjs/load 0.0.2-beta.314 → 0.0.2-beta.320

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
@@ -88,6 +88,8 @@ var import_path2 = require("path");
88
88
  var import_plugin_node_resolve = __toESM(require("@rollup/plugin-node-resolve"));
89
89
  var import_core = require("@swc/core");
90
90
  var FAAS_PACKAGES = [
91
+ "@faasjs/ant-design",
92
+ "@faasjs/aws",
91
93
  "@faasjs/browser",
92
94
  "@faasjs/cli",
93
95
  "@faasjs/cloud_function",
@@ -146,26 +148,50 @@ var NODE_PACKAGES = [
146
148
  "worker_threads",
147
149
  "zlib"
148
150
  ];
149
- function findModule(list, key, basePath, options = { excludes: [] }) {
151
+ function resolveModuleBasePath(moduleName) {
152
+ const moduleMainFilePath = require.resolve(moduleName);
153
+ const moduleNameParts = moduleName.split("/");
154
+ let searchForPathSection;
155
+ if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
156
+ const [org, mod] = moduleNameParts;
157
+ searchForPathSection = `node_modules${import_path2.sep}${org}${import_path2.sep}${mod}`;
158
+ } else {
159
+ const [mod] = moduleNameParts;
160
+ searchForPathSection = `node_modules${import_path2.sep}${mod}`;
161
+ }
162
+ const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
163
+ if (lastIndex === -1) {
164
+ console.log(searchForPathSection, moduleMainFilePath);
165
+ throw new Error(`Couldn't resolve the base path of "${moduleName}". Searched inside the resolved main file path "${moduleMainFilePath}" using "${searchForPathSection}"`);
166
+ }
167
+ return moduleMainFilePath.slice(0, lastIndex + searchForPathSection.length);
168
+ }
169
+ function findModule(list, key, options = { excludes: [] }) {
150
170
  if (list[key])
151
171
  return;
152
172
  if (key.startsWith("@types/") || options.excludes.includes(key))
153
173
  return;
154
- const paths = [(0, import_path2.join)(process.cwd(), "node_modules", key), (0, import_path2.join)(basePath, "node_modules", key)];
155
- let path;
156
- for (const p of paths)
157
- if ((0, import_fs2.existsSync)(p)) {
158
- path = p;
159
- break;
174
+ try {
175
+ list[key] = (0, import_path2.dirname)(require.resolve((0, import_path2.join)(key, "package.json")));
176
+ } catch (error) {
177
+ console.warn(error);
178
+ try {
179
+ list[key] = resolveModuleBasePath(key);
180
+ } catch (error2) {
181
+ console.warn(error2);
160
182
  }
161
- if (!path)
162
- return;
163
- list[key] = path;
164
- if ((0, import_fs2.existsSync)((0, import_path2.join)(path, "package.json"))) {
165
- const pkg = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(path, "package.json")).toString());
166
- const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
167
- deps.map((d) => findModule(list, d, path, options));
168
183
  }
184
+ const pkg = JSON.parse((0, import_fs2.readFileSync)((0, import_path2.join)(list[key], "package.json")).toString());
185
+ const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
186
+ if (pkg.peerDependenciesMeta) {
187
+ Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
188
+ if (pkg.peerDependenciesMeta[key2].optional) {
189
+ const index = deps.indexOf(key2);
190
+ deps.splice(index, 1);
191
+ }
192
+ });
193
+ }
194
+ deps.map((d) => findModule(list, d, options));
169
195
  }
170
196
  function swc(options) {
171
197
  return {
@@ -222,9 +248,9 @@ async function loadTs(filename, options = Object.create(null)) {
222
248
  (0, import_fs2.unlinkSync)(output.file);
223
249
  if (options.modules) {
224
250
  const modules = Object.create(null);
225
- Object.keys(dependencies).map((d) => findModule(modules, d, process.cwd(), options.modules));
251
+ Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
226
252
  if (options.modules.additions)
227
- options.modules.additions.map((d) => findModule(modules, d, process.cwd(), options.modules));
253
+ options.modules.additions.map((d) => findModule(modules, d, options.modules));
228
254
  result.modules = modules;
229
255
  }
230
256
  return result;
package/dist/index.mjs CHANGED
@@ -59,16 +59,18 @@ function loadConfig(root, filename) {
59
59
 
60
60
  // src/load_ts.ts
61
61
  import { deepMerge as deepMerge2 } from "@faasjs/deep_merge";
62
- import {
63
- existsSync as existsSync2,
64
- readFileSync as readFileSync2,
65
- unlinkSync
66
- } from "fs";
62
+ import { readFileSync as readFileSync2, unlinkSync } from "fs";
67
63
  import { rollup } from "rollup";
68
- import { join as join2 } from "path";
64
+ import {
65
+ join as join2,
66
+ sep as sep2,
67
+ dirname as dirname2
68
+ } from "path";
69
69
  import resolve from "@rollup/plugin-node-resolve";
70
70
  import { transform } from "@swc/core";
71
71
  var FAAS_PACKAGES = [
72
+ "@faasjs/ant-design",
73
+ "@faasjs/aws",
72
74
  "@faasjs/browser",
73
75
  "@faasjs/cli",
74
76
  "@faasjs/cloud_function",
@@ -127,26 +129,50 @@ var NODE_PACKAGES = [
127
129
  "worker_threads",
128
130
  "zlib"
129
131
  ];
130
- function findModule(list, key, basePath, options = { excludes: [] }) {
132
+ function resolveModuleBasePath(moduleName) {
133
+ const moduleMainFilePath = __require.resolve(moduleName);
134
+ const moduleNameParts = moduleName.split("/");
135
+ let searchForPathSection;
136
+ if (moduleName.startsWith("@") && moduleNameParts.length > 1) {
137
+ const [org, mod] = moduleNameParts;
138
+ searchForPathSection = `node_modules${sep2}${org}${sep2}${mod}`;
139
+ } else {
140
+ const [mod] = moduleNameParts;
141
+ searchForPathSection = `node_modules${sep2}${mod}`;
142
+ }
143
+ const lastIndex = moduleMainFilePath.lastIndexOf(searchForPathSection);
144
+ if (lastIndex === -1) {
145
+ console.log(searchForPathSection, moduleMainFilePath);
146
+ throw new Error(`Couldn't resolve the base path of "${moduleName}". Searched inside the resolved main file path "${moduleMainFilePath}" using "${searchForPathSection}"`);
147
+ }
148
+ return moduleMainFilePath.slice(0, lastIndex + searchForPathSection.length);
149
+ }
150
+ function findModule(list, key, options = { excludes: [] }) {
131
151
  if (list[key])
132
152
  return;
133
153
  if (key.startsWith("@types/") || options.excludes.includes(key))
134
154
  return;
135
- const paths = [join2(process.cwd(), "node_modules", key), join2(basePath, "node_modules", key)];
136
- let path;
137
- for (const p of paths)
138
- if (existsSync2(p)) {
139
- path = p;
140
- break;
155
+ try {
156
+ list[key] = dirname2(__require.resolve(join2(key, "package.json")));
157
+ } catch (error) {
158
+ console.warn(error);
159
+ try {
160
+ list[key] = resolveModuleBasePath(key);
161
+ } catch (error2) {
162
+ console.warn(error2);
141
163
  }
142
- if (!path)
143
- return;
144
- list[key] = path;
145
- if (existsSync2(join2(path, "package.json"))) {
146
- const pkg = JSON.parse(readFileSync2(join2(path, "package.json")).toString());
147
- const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
148
- deps.map((d) => findModule(list, d, path, options));
149
164
  }
165
+ const pkg = JSON.parse(readFileSync2(join2(list[key], "package.json")).toString());
166
+ const deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
167
+ if (pkg.peerDependenciesMeta) {
168
+ Object.keys(pkg.peerDependenciesMeta).forEach((key2) => {
169
+ if (pkg.peerDependenciesMeta[key2].optional) {
170
+ const index = deps.indexOf(key2);
171
+ deps.splice(index, 1);
172
+ }
173
+ });
174
+ }
175
+ deps.map((d) => findModule(list, d, options));
150
176
  }
151
177
  function swc(options) {
152
178
  return {
@@ -203,9 +229,9 @@ async function loadTs(filename, options = Object.create(null)) {
203
229
  unlinkSync(output.file);
204
230
  if (options.modules) {
205
231
  const modules = Object.create(null);
206
- Object.keys(dependencies).map((d) => findModule(modules, d, process.cwd(), options.modules));
232
+ Object.keys(dependencies).map((d) => findModule(modules, d, options.modules));
207
233
  if (options.modules.additions)
208
- options.modules.additions.map((d) => findModule(modules, d, process.cwd(), options.modules));
234
+ options.modules.additions.map((d) => findModule(modules, d, options.modules));
209
235
  result.modules = modules;
210
236
  }
211
237
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "0.0.2-beta.314",
3
+ "version": "0.0.2-beta.320",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "dist"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@faasjs/deep_merge": "^0.0.2-beta.244",
26
- "@faasjs/func": "^0.0.2-beta.302",
25
+ "@faasjs/deep_merge": "^0.0.2-beta.320",
26
+ "@faasjs/func": "^0.0.2-beta.320",
27
27
  "@rollup/plugin-node-resolve": "*",
28
28
  "@swc/core": "*",
29
29
  "js-yaml": "*",
@@ -37,5 +37,5 @@
37
37
  "engines": {
38
38
  "npm": ">=8.0.0"
39
39
  },
40
- "gitHead": "60be0e54eb369177b416d109a3f9a5a12dedbf24"
40
+ "gitHead": "4a9f699171ad7e20d922e68b74418d1ec5b7d016"
41
41
  }