cloud-run-functions 0.1.2 → 0.1.3

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/main.js CHANGED
@@ -1,29 +1,53 @@
1
1
  // src/main.ts
2
- import * as ordana from "ordana";
3
- var command = ordana.parse(process.argv.slice(2), {
2
+ import {
3
+ command,
4
+ option,
5
+ optional,
6
+ positional,
7
+ run,
8
+ string,
9
+ subcommands
10
+ } from "cmd-ts";
11
+ var dev = command({
12
+ name: "dev",
13
+ description: "Start the development server",
14
+ args: {
15
+ root: positional({
16
+ type: optional(string),
17
+ displayName: "root",
18
+ description: "Directory to search for function entrypoints"
19
+ }),
20
+ port: option({
21
+ type: optional(string),
22
+ long: "port",
23
+ short: "p",
24
+ description: "The port to use for the development server"
25
+ })
26
+ },
27
+ async handler({ root, port }) {
28
+ const { dev: dev2 } = await import("./tools/dev.js");
29
+ await dev2(root, { port });
30
+ }
31
+ });
32
+ var build = command({
33
+ name: "build",
34
+ description: "Generate a bundle for each function",
35
+ args: {
36
+ root: positional({
37
+ type: optional(string),
38
+ displayName: "root",
39
+ description: "Directory to search for function entrypoints"
40
+ })
41
+ },
42
+ async handler() {
43
+ throw new Error("Not implemented");
44
+ }
45
+ });
46
+ var cli = subcommands({
4
47
  name: "cloud-run-functions",
5
- subcommands: {
6
- dev: {
7
- description: "Start the development server",
8
- positionals: { maximum: 1 }
9
- },
10
- build: {
11
- description: "Generate a bundle for each function",
12
- positionals: { maximum: 1 }
13
- }
48
+ cmds: {
49
+ dev,
50
+ build
14
51
  }
15
52
  });
16
- if (command.type === "help") {
17
- console.log(ordana.generateHelpMessage(command));
18
- } else {
19
- const subcommands = {
20
- async dev() {
21
- const { dev } = await import("./tools/dev.js");
22
- await dev(command.positionals[0]);
23
- },
24
- async build() {
25
- throw new Error("Not implemented");
26
- }
27
- };
28
- await subcommands[command.subcommand]();
29
- }
53
+ await run(cli, process.argv.slice(2));
@@ -6,7 +6,7 @@ import { findUpSync } from "find-up-simple";
6
6
  import fs2 from "node:fs";
7
7
  import { Module } from "node:module";
8
8
  import os from "node:os";
9
- import path2 from "node:path";
9
+ import path3 from "node:path";
10
10
 
11
11
  // node_modules/.pnpm/radashi@12.4.0/node_modules/radashi/dist/radashi.js
12
12
  var TimeoutError = class extends Error {
@@ -74,10 +74,54 @@ function isTagged(value, tag) {
74
74
  return Object.prototype.toString.call(value) === tag;
75
75
  }
76
76
 
77
+ // src/common/emptyDir.ts
78
+ import fs from "node:fs";
79
+ function emptyDir(dir) {
80
+ fs.rmSync(dir, { recursive: true, force: true });
81
+ fs.mkdirSync(dir, { recursive: true });
82
+ return dir;
83
+ }
84
+
85
+ // src/common/functionFilter.ts
86
+ import path from "node:path";
87
+ function getFunctionFilter(options) {
88
+ const functionGlobs = [];
89
+ const functionSuffixes = /* @__PURE__ */ new Set();
90
+ const requiredSuffix = options.entrySuffix?.replace(/^\.?/, ".") ?? "";
91
+ for (const glob of options.globs ?? ["**/*"]) {
92
+ let ext = path.extname(glob);
93
+ if (ext) {
94
+ functionSuffixes.add(requiredSuffix + ext);
95
+ functionGlobs.push(
96
+ requiredSuffix ? glob.replace(ext, requiredSuffix + ext) : glob
97
+ );
98
+ continue;
99
+ }
100
+ for (ext of options.extensions ?? [".ts", ".js"]) {
101
+ ext = requiredSuffix + ext;
102
+ functionSuffixes.add(ext);
103
+ functionGlobs.push(glob + ext);
104
+ }
105
+ }
106
+ const suffixPattern = new RegExp(
107
+ `(${Array.from(functionSuffixes, (e) => e.replace(/\./g, "\\.")).sort((a, b) => b.length - a.length).join("|")})$`
108
+ );
109
+ return {
110
+ globs: functionGlobs,
111
+ suffixPattern
112
+ };
113
+ }
114
+
115
+ // src/common/hash.ts
116
+ import crypto from "node:crypto";
117
+ function hash(data, len) {
118
+ return crypto.createHash("sha256").update(data).digest("hex").slice(0, len);
119
+ }
120
+
77
121
  // src/config/index.ts
78
122
  import * as z2 from "@zod/mini";
79
123
  import Joycon from "joycon";
80
- import path from "node:path";
124
+ import path2 from "node:path";
81
125
 
82
126
  // src/config/schema.ts
83
127
  import * as z from "@zod/mini";
@@ -141,53 +185,19 @@ function loadConfig(cwd) {
141
185
  }
142
186
  return {
143
187
  ...z2.parse(configSchema, result.data),
144
- configDir: path.dirname(result.path)
188
+ configDir: path2.dirname(result.path)
145
189
  };
146
190
  }
147
191
 
148
- // src/utils/emptyDir.ts
149
- import fs from "node:fs";
150
- function emptyDir(dir) {
151
- fs.rmSync(dir, { recursive: true, force: true });
152
- fs.mkdirSync(dir, { recursive: true });
153
- return dir;
154
- }
155
-
156
- // src/utils/hash.ts
157
- import crypto from "node:crypto";
158
- function hash(data, len) {
159
- return crypto.createHash("sha256").update(data).digest("hex").slice(0, len);
160
- }
161
-
162
192
  // src/targets/dev.ts
163
193
  async function createBuild() {
164
194
  const options = JSON.parse(process.env.CRF_OPTIONS);
165
- const searchDir = path2.resolve(options.workingDir, options.searchDir ?? "");
195
+ const searchDir = path3.resolve(options.workingDir, options.searchDir ?? "");
166
196
  const config = loadConfig(searchDir);
167
- const root = config.configDir ? path2.resolve(config.configDir, config.root ?? "") : searchDir;
168
- const entryPoints = [];
169
- const requiredSuffix = config.entrySuffix?.replace(/^\.?/, ".") ?? "";
170
- const knownSuffixes = /* @__PURE__ */ new Set();
171
- for (const glob of config.globs ?? ["**/*"]) {
172
- let ext = path2.extname(glob);
173
- if (ext) {
174
- knownSuffixes.add(requiredSuffix + ext);
175
- entryPoints.push(
176
- requiredSuffix ? glob.replace(ext, requiredSuffix + ext) : glob
177
- );
178
- continue;
179
- }
180
- for (ext of config.extensions ?? [".ts", ".js"]) {
181
- ext = requiredSuffix + ext;
182
- knownSuffixes.add(ext);
183
- entryPoints.push(glob + ext);
184
- }
185
- }
186
- const knownSuffixesRE = new RegExp(
187
- `(${Array.from(knownSuffixes, (e) => e.replace(/\./g, "\\.")).sort((a, b) => b.length - a.length).join("|")})$`
188
- );
197
+ const root = config.configDir ? path3.resolve(config.configDir, config.root ?? "") : searchDir;
198
+ const functionFilter = getFunctionFilter(config);
189
199
  const cacheDir = emptyDir(
190
- path2.join(
200
+ path3.join(
191
201
  fs2.realpathSync(os.tmpdir()),
192
202
  "cloud-run-functions-" + hash(root, 8)
193
203
  )
@@ -195,7 +205,7 @@ async function createBuild() {
195
205
  let pendingBuild;
196
206
  let finishedBuild;
197
207
  const context = await esbuild.context({
198
- entryPoints,
208
+ entryPoints: functionFilter.globs,
199
209
  absWorkingDir: root,
200
210
  outdir: cacheDir,
201
211
  define: options.define,
@@ -252,7 +262,10 @@ async function createBuild() {
252
262
  if (!output.entryPoint) {
253
263
  continue;
254
264
  }
255
- const taskName = output.entryPoint.replace(knownSuffixesRE, "");
265
+ const taskName = output.entryPoint.replace(
266
+ functionFilter.suffixPattern,
267
+ ""
268
+ );
256
269
  if (url.pathname === "/" + taskName) {
257
270
  const taskState = taskStates.get(taskName) ?? {
258
271
  running: 0,
@@ -274,7 +287,7 @@ async function createBuild() {
274
287
  taskState.running++;
275
288
  taskStates.set(taskName, taskState);
276
289
  const require2 = Module.createRequire(import.meta.filename);
277
- let taskHandler = require2(path2.join(root, file));
290
+ let taskHandler = require2(path3.join(root, file));
278
291
  while (taskHandler && typeof taskHandler !== "function") {
279
292
  taskHandler = taskHandler.default;
280
293
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-run-functions",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "bin": "./dist/main.js",
6
6
  "exports": {
7
7
  "types": "./dist/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@zod/mini": "4.0.0-beta.0",
38
+ "cmd-ts": "^0.14.3",
38
39
  "esbuild": "^0.25.4",
39
40
  "find-up-simple": "^1.0.1",
40
41
  "joycon": "^3.1.1",
41
- "ordana": "^0.4.0",
42
42
  "picospawn": "^0.3.2",
43
43
  "source-map-support": "^0.5.21",
44
44
  "tinyglobby": "^0.2.13"