as-soon 0.0.1 → 0.0.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/cli.cjs CHANGED
@@ -47,7 +47,8 @@ var __async = (__this, __arguments, generator) => {
47
47
  var import_child_process = require("child_process");
48
48
  var import_watcher = __toESM(require("@parcel/watcher"), 1);
49
49
  var import_node_path = __toESM(require("path"), 1);
50
- var import_lodash_es = require("lodash-es");
50
+ var import_node_fs = __toESM(require("fs"), 1);
51
+ var import_lodash = require("lodash");
51
52
  var import_ldenv = require("ldenv");
52
53
  var args = process.argv.slice(2);
53
54
  function error(msg) {
@@ -90,14 +91,47 @@ function _execute() {
90
91
  (0, import_child_process.execFileSync)(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
91
92
  });
92
93
  }
94
+ function subscribe_target(absolute_path, execute) {
95
+ return __async(this, null, function* () {
96
+ const p = import_node_path.default.relative(process.cwd(), absolute_path);
97
+ const subscription = yield import_watcher.default.subscribe(absolute_path, (err, events) => {
98
+ console.log(`Files changed under ${p}`);
99
+ for (const event of events) {
100
+ if (event.type === "delete" && event.path === absolute_path) {
101
+ subscription.unsubscribe();
102
+ listen(absolute_path, execute);
103
+ return;
104
+ }
105
+ }
106
+ execute();
107
+ });
108
+ });
109
+ }
110
+ function listen(absolute_path, execute) {
111
+ return __async(this, null, function* () {
112
+ if (import_node_fs.default.existsSync(absolute_path)) {
113
+ subscribe_target(absolute_path, execute);
114
+ } else {
115
+ let tmp_subscription = yield import_watcher.default.subscribe(import_node_path.default.dirname(absolute_path), (err, events) => {
116
+ for (const event of events) {
117
+ if (event.type === "create" && import_node_path.default.normalize(event.path) === absolute_path) {
118
+ tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
119
+ tmp_subscription = void 0;
120
+ setTimeout((v) => {
121
+ subscribe_target(absolute_path, execute);
122
+ }, 500);
123
+ }
124
+ }
125
+ });
126
+ }
127
+ });
128
+ }
93
129
  function main() {
94
130
  return __async(this, null, function* () {
95
- const execute = (0, import_lodash_es.debounce)(_execute, 50);
131
+ const execute = (0, import_lodash.debounce)(_execute, 50);
96
132
  for (const p of options["w"]) {
97
- import_watcher.default.subscribe(import_node_path.default.join(process.cwd(), p), (err, events) => {
98
- console.log(`Files changed under ${p}`);
99
- execute();
100
- });
133
+ const absolute_path = import_node_path.default.normalize(import_node_path.default.join(process.cwd(), p));
134
+ listen(absolute_path, execute);
101
135
  }
102
136
  execute();
103
137
  });
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { execFileSync } from 'child_process';\nimport watcher from \"@parcel/watcher\";\nimport path from \"node:path\";\nimport { debounce } from \"lodash-es\";\nimport { loadEnv } from \"ldenv\";\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n console.error(msg);\n process.exit(1);\n}\n\nlet deploymentContext = \"localhost\";\nlet argToConsume;\nlet command: string | undefined;\nlet commandArgs: string[] | undefined;\nconst options: { [key: string]: string[] } = {};\nfor (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n\nasync function main() {\n const execute = debounce(_execute, 50);\n for (const p of options[\"w\"]) {\n watcher.subscribe(path.join(process.cwd(), p), (err, events) => {\n console.log(`Files changed under ${p}`)\n execute();\n });\n }\n execute();\n}\nmain();\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QAAQ,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,WAAW;AAC9D,gBAAQ,IAAI,uBAAuB,GAAG;AACtC,gBAAQ;AAAA,MACV,CAAC;AAAA,IACH;AACA,YAAQ;AAAA,EACV;AAAA;AACA,KAAK;","names":["watcher","path"]}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { execFileSync } from 'child_process';\nimport watcher, { AsyncSubscription } from \"@parcel/watcher\";\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport { debounce } from \"lodash\";\nimport { loadEnv } from \"ldenv\";\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n console.error(msg);\n process.exit(1);\n}\n\nlet deploymentContext = \"localhost\";\nlet argToConsume;\nlet command: string | undefined;\nlet commandArgs: string[] | undefined;\nconst options: { [key: string]: string[] } = {};\nfor (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\n // const c = ++counter;\n const p = path.relative(process.cwd(), absolute_path);\n const subscription = await watcher.subscribe(absolute_path, (err, events) => {\n // console.log(`Files changed under ${p} (${c})`);\n console.log(`Files changed under ${p}`);\n for (const event of events) {\n if (event.type === 'delete' && event.path === absolute_path) {\n subscription.unsubscribe();\n listen(absolute_path, execute);\n return;\n }\n }\n execute();\n });\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n if (fs.existsSync(absolute_path)) {\n subscribe_target(absolute_path, execute);\n } else {\n // console.log(`${absolute_path} do not exist yet, listening on parent`)\n let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(path.dirname(absolute_path), (err, events) => {\n for (const event of events) {\n if (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n // console.log(`${absolute_path} just got created, listening for it...`);\n tmp_subscription?.unsubscribe();\n tmp_subscription = undefined;\n // wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n setTimeout(v => {\n subscribe_target(absolute_path, execute);\n }, 500);\n }\n }\n });\n }\n}\n\nasync function main() {\n const execute = debounce(_execute, 50);\n for (const p of options[\"w\"]) {\n const absolute_path = path.normalize(path.join(process.cwd(), p));\n listen(absolute_path, execute);\n }\n execute();\n}\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA6B;AAC7B,qBAA2C;AAC3C,uBAAiB;AACjB,qBAAe;AACf,oBAAyB;AACzB,mBAAwB;AAExB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,MAAM,KAAa;AAC1B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAI,oBAAoB;AACxB,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAM,UAAuC,CAAC;AAC9C,SAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,IAAI,WAAW,IAAI,GAAG;AACxB,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,WAAW,IAAI,WAAW,GAAG,GAAG;AAC9B,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,OAAO;AACL,QAAI,cAAc;AAChB,UAAI,QAAQ,YAAY,GAAG;AACzB,gBAAQ,YAAY,EAAE,KAAK,GAAG;AAAA,MAChC,OAAO;AACL,g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AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAEA,SAAe,OAAO;AAAA;AACpB,UAAM,cAAU,wBAAS,UAAU,EAAE;AACrC,eAAW,KAAK,QAAQ,GAAG,GAAG;AAC5B,YAAM,gBAAgB,iBAAAA,QAAK,UAAU,iBAAAA,QAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,aAAO,eAAe,OAAO;AAAA,IAC/B;AACA,YAAQ;AAAA,EACV;AAAA;AACA,KAAK;","names":["path","watcher","fs"]}
package/dist/cli.js CHANGED
@@ -7,7 +7,8 @@ import {
7
7
  import { execFileSync } from "child_process";
8
8
  import watcher from "@parcel/watcher";
9
9
  import path from "path";
10
- import { debounce } from "lodash-es";
10
+ import fs from "fs";
11
+ import { debounce } from "lodash";
11
12
  import { loadEnv } from "ldenv";
12
13
  var args = process.argv.slice(2);
13
14
  function error(msg) {
@@ -50,14 +51,47 @@ function _execute() {
50
51
  execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
51
52
  });
52
53
  }
54
+ function subscribe_target(absolute_path, execute) {
55
+ return __async(this, null, function* () {
56
+ const p = path.relative(process.cwd(), absolute_path);
57
+ const subscription = yield watcher.subscribe(absolute_path, (err, events) => {
58
+ console.log(`Files changed under ${p}`);
59
+ for (const event of events) {
60
+ if (event.type === "delete" && event.path === absolute_path) {
61
+ subscription.unsubscribe();
62
+ listen(absolute_path, execute);
63
+ return;
64
+ }
65
+ }
66
+ execute();
67
+ });
68
+ });
69
+ }
70
+ function listen(absolute_path, execute) {
71
+ return __async(this, null, function* () {
72
+ if (fs.existsSync(absolute_path)) {
73
+ subscribe_target(absolute_path, execute);
74
+ } else {
75
+ let tmp_subscription = yield watcher.subscribe(path.dirname(absolute_path), (err, events) => {
76
+ for (const event of events) {
77
+ if (event.type === "create" && path.normalize(event.path) === absolute_path) {
78
+ tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
79
+ tmp_subscription = void 0;
80
+ setTimeout((v) => {
81
+ subscribe_target(absolute_path, execute);
82
+ }, 500);
83
+ }
84
+ }
85
+ });
86
+ }
87
+ });
88
+ }
53
89
  function main() {
54
90
  return __async(this, null, function* () {
55
91
  const execute = debounce(_execute, 50);
56
92
  for (const p of options["w"]) {
57
- watcher.subscribe(path.join(process.cwd(), p), (err, events) => {
58
- console.log(`Files changed under ${p}`);
59
- execute();
60
- });
93
+ const absolute_path = path.normalize(path.join(process.cwd(), p));
94
+ listen(absolute_path, execute);
61
95
  }
62
96
  execute();
63
97
  });
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { execFileSync } from 'child_process';\nimport watcher from \"@parcel/watcher\";\nimport path from \"node:path\";\nimport { debounce } from \"lodash-es\";\nimport { loadEnv } from \"ldenv\";\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n console.error(msg);\n process.exit(1);\n}\n\nlet deploymentContext = \"localhost\";\nlet argToConsume;\nlet command: string | undefined;\nlet commandArgs: string[] | undefined;\nconst options: { [key: string]: string[] } = {};\nfor (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n\nasync function main() {\n const execute = debounce(_execute, 50);\n for (const p of options[\"w\"]) {\n watcher.subscribe(path.join(process.cwd(), p), (err, events) => {\n console.log(`Files changed under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GAAG,CAAC,GAAG,CAAC,KAAK,WAAW;AAC9D,gBAAQ,IAAI,uBAAuB,GAAG;AACtC,gBAAQ;AAAA,MACV,CAAC;AAAA,IACH;AACA,YAAQ;AAAA,EACV;AAAA;AACA,KAAK;","names":[]}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { execFileSync } from 'child_process';\nimport watcher, { AsyncSubscription } from \"@parcel/watcher\";\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport { debounce } from \"lodash\";\nimport { loadEnv } from \"ldenv\";\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n console.error(msg);\n process.exit(1);\n}\n\nlet deploymentContext = \"localhost\";\nlet argToConsume;\nlet command: string | undefined;\nlet commandArgs: string[] | undefined;\nconst options: { [key: string]: string[] } = {};\nfor (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\n // const c = ++counter;\n const p = path.relative(process.cwd(), absolute_path);\n const subscription = await watcher.subscribe(absolute_path, (err, events) => {\n // console.log(`Files changed under ${p} (${c})`);\n console.log(`Files changed under ${p}`);\n for (const event of events) {\n if (event.type === 'delete' && event.path === absolute_path) {\n subscription.unsubscribe();\n listen(absolute_path, execute);\n return;\n }\n }\n execute();\n });\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n if (fs.existsSync(absolute_path)) {\n subscribe_target(absolute_path, execute);\n } else {\n // console.log(`${absolute_path} do not exist yet, listening on parent`)\n let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(path.dirname(absolute_path), (err, events) => {\n for (const event of events) {\n if (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n // console.log(`${absolute_path} just got created, listening for it...`);\n tmp_subscription?.unsubscribe();\n tmp_subscription = undefined;\n // wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n setTimeout(v => {\n subscribe_target(absolute_path, execute);\n }, 500);\n }\n }\n });\n }\n}\n\nasync function main() {\n const execute = debounce(_execute, 50);\n for (const p of options[\"w\"]) {\n const absolute_path = path.normalize(path.join(process.cwd(), p));\n listen(absolute_path, execute);\n }\n execute();\n}\nmain();\n"],"mappings":";;;;;;AACA,SAAS,oBAAoB;AAC7B,OAAO,aAAoC;AAC3C,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAExB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,MAAM,KAAa;AAC1B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAI,oBAAoB;AACxB,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAM,UAAuC,CAAC;AAC9C,SAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,IAAI,WAAW,IAAI,GAAG;AACxB,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,WAAW,IAAI,WAAW,GAAG,GAAG;AAC9B,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,OAAO;AACL,QAAI,cAAc;AAChB,UAAI,QAAQ,YAAY,GAAG;AACzB,gBAAQ,YAAY,EAAE,KAAK,GAAG;AAAA,MAChC,OAAO;AACL,gBAAQ,YAAY,IAAI,CAAC,GAAG;AAAA,M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AAU,SAAS,UAAU,EAAE;AACrC,eAAW,KAAK,QAAQ,GAAG,GAAG;AAC5B,YAAM,gBAAgB,KAAK,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,aAAO,eAAe,OAAO;AAAA,IAC/B;AACA,YAAQ;AAAA,EACV;AAAA;AACA,KAAK;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-soon",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "watch and execute",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,9 +15,11 @@
15
15
  "dependencies": {
16
16
  "@parcel/watcher": "^2.1.0",
17
17
  "ldenv": "^0.2.1",
18
+ "lodash": "^4.17.21",
18
19
  "lodash-es": "^4.17.21"
19
20
  },
20
21
  "devDependencies": {
22
+ "@types/lodash": "^4.14.194",
21
23
  "@types/lodash-es": "^4.17.7",
22
24
  "@types/node": "^18.15.5",
23
25
  "set-defaults": "^0.0.1",
package/src/cli.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { execFileSync } from 'child_process';
3
- import watcher from "@parcel/watcher";
3
+ import watcher, { AsyncSubscription } from "@parcel/watcher";
4
4
  import path from "node:path";
5
- import { debounce } from "lodash-es";
5
+ import fs from "node:fs";
6
+ import { debounce } from "lodash";
6
7
  import { loadEnv } from "ldenv";
7
8
 
8
9
  const args = process.argv.slice(2);
@@ -50,14 +51,50 @@ async function _execute() {
50
51
  execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
51
52
  }
52
53
 
54
+ // let counter = 0;
55
+ async function subscribe_target(absolute_path: string, execute: () => void) {
56
+ // const c = ++counter;
57
+ const p = path.relative(process.cwd(), absolute_path);
58
+ const subscription = await watcher.subscribe(absolute_path, (err, events) => {
59
+ // console.log(`Files changed under ${p} (${c})`);
60
+ console.log(`Files changed under ${p}`);
61
+ for (const event of events) {
62
+ if (event.type === 'delete' && event.path === absolute_path) {
63
+ subscription.unsubscribe();
64
+ listen(absolute_path, execute);
65
+ return;
66
+ }
67
+ }
68
+ execute();
69
+ });
70
+ }
71
+
72
+ async function listen(absolute_path: string, execute: () => void) {
73
+ if (fs.existsSync(absolute_path)) {
74
+ subscribe_target(absolute_path, execute);
75
+ } else {
76
+ // console.log(`${absolute_path} do not exist yet, listening on parent`)
77
+ let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(path.dirname(absolute_path), (err, events) => {
78
+ for (const event of events) {
79
+ if (event.type === 'create' && path.normalize(event.path) === absolute_path) {
80
+ // console.log(`${absolute_path} just got created, listening for it...`);
81
+ tmp_subscription?.unsubscribe();
82
+ tmp_subscription = undefined;
83
+ // wrap in a timeout to ensure @parcel/watcher hook on the correct inode?
84
+ setTimeout(v => {
85
+ subscribe_target(absolute_path, execute);
86
+ }, 500);
87
+ }
88
+ }
89
+ });
90
+ }
91
+ }
53
92
 
54
93
  async function main() {
55
94
  const execute = debounce(_execute, 50);
56
95
  for (const p of options["w"]) {
57
- watcher.subscribe(path.join(process.cwd(), p), (err, events) => {
58
- console.log(`Files changed under ${p}`)
59
- execute();
60
- });
96
+ const absolute_path = path.normalize(path.join(process.cwd(), p));
97
+ listen(absolute_path, execute);
61
98
  }
62
99
  execute();
63
100
  }
package/.env DELETED
@@ -1,5 +0,0 @@
1
- HELLO=bonjour
2
- WORLD=$HELLO
3
- ENV_MODE=DEPLOYMENT_CONTEXT
4
- # RPC_URL=locl45
5
- RPC_URL_localhost=lsakdlsakdlkdlk
package/.env.production DELETED
@@ -1 +0,0 @@
1
- HELLO="prod"
package/script.sh DELETED
@@ -1,4 +0,0 @@
1
- echo received: "$@"
2
- echo "will fail"
3
- echo "Error!" 1>&2
4
- exit 1
package/src/utils.ts DELETED
@@ -1,25 +0,0 @@
1
- // taken from https://github.com/vitejs/vite/blob/63524bac878e8d3771d34ad7ad2e10cd16870ff4/packages/vite/src/node/utils.ts#L371-L400
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
-
5
- interface LookupFileOptions {
6
- pathOnly?: boolean;
7
- rootDir?: string;
8
- predicate?: (file: string) => boolean;
9
- }
10
-
11
- export function lookupFile(dir: string, formats: string[], options?: LookupFileOptions): string | undefined {
12
- for (const format of formats) {
13
- const fullPath = path.join(dir, format);
14
- if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()) {
15
- const result = options?.pathOnly ? fullPath : fs.readFileSync(fullPath, 'utf-8');
16
- if (!options?.predicate || options.predicate(result)) {
17
- return result;
18
- }
19
- }
20
- }
21
- const parentDir = path.dirname(dir);
22
- if (parentDir !== dir && (!options?.rootDir || parentDir.startsWith(options?.rootDir))) {
23
- return lookupFile(parentDir, formats, options);
24
- }
25
- }