@stackone/cli 1.7.0 → 1.8.0
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 +51 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/cliCore-BOwdDcP4.cjs +7 -0
- package/dist/cliCore-CYhcPSJT.js +7 -0
- package/dist/{esm-Chmlhd00.cjs → esm-BrK-ICga.cjs} +1 -1
- package/dist/{esm-BenXeAeS.js → esm-D_hUWJ1V.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/cliCore-PXfmff5l.cjs +0 -5
- package/dist/cliCore-eRQ8Iw8F.js +0 -5
package/README.md
CHANGED
|
@@ -21,6 +21,57 @@ stackone -h
|
|
|
21
21
|
|
|
22
22
|
## Commands
|
|
23
23
|
|
|
24
|
+
### `init`
|
|
25
|
+
|
|
26
|
+
Initialize and configure the StackOne CLI by creating configuration profiles. This command allows you to store multiple configuration profiles for easy access.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
stackone init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The command will interactively prompt you for:
|
|
33
|
+
|
|
34
|
+
1. **Profile label** - A unique name for this configuration profile
|
|
35
|
+
2. **Environment** - Choose from:
|
|
36
|
+
- `production`
|
|
37
|
+
- `staging`
|
|
38
|
+
- `local`
|
|
39
|
+
3. **API Key** - Your StackOne API key
|
|
40
|
+
|
|
41
|
+
**Features:**
|
|
42
|
+
|
|
43
|
+
- **Multiple configurations**: Store different configs for various environments
|
|
44
|
+
- **Overwrite protection**: Prompts for confirmation before overwriting existing configs
|
|
45
|
+
- **Persistent storage**: Configurations are saved in `~/.stackone`
|
|
46
|
+
- **Reusable**: Run the command multiple times to create different configurations
|
|
47
|
+
|
|
48
|
+
### `push`
|
|
49
|
+
|
|
50
|
+
Push connector(s) file(s) to the StackOne API registry. This command requires a configuration profile created with the `init` command.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
stackone push --profile <profile-label> path/to/connector.s1.yaml
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
or
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
stackone push --profile <profile-label> path/to/connectors/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Arguments:**
|
|
63
|
+
|
|
64
|
+
- `<path>` - Path to the connector file or folder with connectors to upload
|
|
65
|
+
|
|
66
|
+
**Options:**
|
|
67
|
+
|
|
68
|
+
- `-p, --profile <label>` - Configuration profile to use (required)
|
|
69
|
+
|
|
70
|
+
**Features:**
|
|
71
|
+
|
|
72
|
+
- **Profile validation**: Ensures the specified profile exists before uploading
|
|
73
|
+
- **File validation**: Checks that the file exists and is a valid connector before attempting upload
|
|
74
|
+
|
|
24
75
|
### `validate`
|
|
25
76
|
|
|
26
77
|
Validate a StackOne connector file:
|
package/dist/cli.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require(`./cliCore-
|
|
2
|
+
const e=require(`./cliCore-BOwdDcP4.cjs`),t=new e.CLI;t.run();
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{CLI as e}from"./cliCore-
|
|
2
|
+
import{CLI as e}from"./cliCore-CYhcPSJT.js";const t=new e;t.run();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`chalk`)),n=e.__toESM(require(`commander`)),r=e.__toESM(require(`inquirer`)),i=e.__toESM(require(`fs`)),a=e.__toESM(require(`os`)),o=e.__toESM(require(`path`)),s=e.__toESM(require(`@stackone/connect-sdk`)),c=e.__toESM(require(`ora`)),l=e.__toESM(require(`url`)),u=(0,o.join)((0,a.homedir)(),`.stackone`),d={profiles:{}},f=()=>{if(!(0,i.existsSync)(u))return d;try{let e=(0,i.readFileSync)(u,`utf-8`);return JSON.parse(e)}catch{return d}},p=e=>{let t=f();return t.profiles[e]},m=e=>{let t=f();return!!t.profiles[e]},h=(e,t)=>{let n=f();n.profiles[e]=t;let r=(0,o.join)((0,a.homedir)());(0,i.existsSync)(r)||(0,i.mkdirSync)(r,{recursive:!0}),(0,i.writeFileSync)(u,JSON.stringify(n,null,2),`utf-8`)},g=()=>{let e=f();return Object.keys(e.profiles)};var _=class{static info(e){console.info(t.default.blue(`ℹ`),e)}static warn(e){console.info(t.default.yellow(`⚠`),e)}static error(e){console.info(t.default.red(`✗`),e)}static success(e){console.info(t.default.green(`✓`),e)}};const v=`https://api.stackone.com`,y=`https://api.stackone-dev.com`,b=`http://localhost:4000`;var x=class{async execute(){try{let{label:e}=await r.default.prompt([{type:`input`,name:`label`,message:`Profile label:`,validate:e=>!e||e.trim().length===0?`The profile label is required`:e.includes(` `)?`The profile label cannot contain spaces`:!0}]);if(m(e)){let{overwrite:t}=await r.default.prompt([{type:`confirm`,name:`overwrite`,message:`Configuration profile with name "${e}" already exists. Do you want to overwrite it?`,default:!1}]);t||(_.info(`Configuration profile initialization cancelled`),process.exit(0))}let{environment:n}=await r.default.prompt([{type:`list`,name:`environment`,message:`Environment:`,choices:[`production`,`staging`,`local`]}]),i;if(n===`production`)i=v;else if(n===`staging`)i=y;else{let{customUrl:e}=await r.default.prompt([{type:`input`,name:`customUrl`,message:`API URL:`,default:b,validate:e=>{if(!e||e.trim().length===0)return`API URL is required`;try{return new URL(e),!0}catch{return`Please enter a valid URL`}}}]);i=e}let{apiKey:a}=await r.default.prompt([{type:`password`,name:`apiKey`,message:`API Key:`,validate:e=>!e||e.trim().length===0?`API Key is required`:!0}]),o={label:e,environment:n,apiUrl:i,apiKey:a};h(e,o),console.info(t.default.green(`\n✓ Configuration profile "${e}" saved successfully`)),process.exit(0)}catch(e){e.isTtyError?_.error(`Prompt couldn't be rendered in the current environment`):_.error(`Failed to initialize configuration profile: ${e}`),process.exit(1)}}},S=class{async execute(e){let{profile:t,fileOrDir:n}=e;if(t||(_.error(`Profile is required. Use --profile <label> to specify a configuration.`),_.info(`Run "stackone init" to create a new configuration profile.`),process.exit(1)),!m(t)){_.error(`Configuration profile "${t}" not found.`),_.info(`Run "stackone init" to create a new configuration profile.`);let e=g();_.info(`Available profiles: ${e.join(`, `)||`none`}`),process.exit(1)}let r=p(t);r||(_.error(`Failed to load configuration profile "${t}".`),process.exit(1)),n||(_.error(`File or directory path is required.`),process.exit(1));try{(0,i.statSync)(n)}catch{_.error(`File or directory not found: ${n}`),process.exit(1)}let a=(0,i.statSync)(n);if(a.isDirectory()){let e=w(n),t=0;e.length===0?(_.error(`No .s1.yaml connector files found in the directory: ${n}.`),process.exit(1)):_.info(`Found ${e.length} connector(s) file(s). Processing...`);for(let n of e){console.info(`
|
|
2
|
+
`);let e=await this.uploadFile(n,r.apiUrl,r.apiKey);e&&t++}console.info(`
|
|
3
|
+
`),_.info(`Upload completed: ${t} of ${e.length} file(s) uploaded successfully.`),process.exit(t>0?0:1)}else n.endsWith(`.s1.yaml`)||(_.error(`Only .s1.yaml files are supported for upload.`),process.exit(1));let o=await this.uploadFile(n,r.apiUrl,r.apiKey);process.exit(o?0:1)}async uploadFile(e,n,r){try{console.info(t.default.blue(`📤 Uploading ${(0,o.basename)(e)}...`));let i=C(e);if(!i)return!1;let a=(0,o.basename)(e),s=new FormData,c=new Blob([i],{type:`application/x-yaml`});s.append(`file`,c,a);let l=Buffer.from(r).toString(`base64`),u=await fetch(`${n}/registry/connectors`,{method:`POST`,headers:{Authorization:`Basic ${l}`},body:s});if(!u.ok){let e=await u.text();return _.error(`Upload failed: ${u.status} - ${u.statusText}`),e&&console.error(t.default.red(e)),!1}let d=await u.json();return console.info(t.default.green(`✓ Successfully uploaded ${a} with connector "${d.provider}@${d.version}"`)),!0}catch(e){return _.error(`Failed to upload file: ${e}`),!1}}};const C=e=>{let n=(0,s.loadConnector)(e),r=(0,s.validateYamlConnector)(n),i=r?.errors??[];if(r.success){let t=e.split(`/`).pop()||e;return _.success(`Connector ${t} is valid!`),n}else i.length>0?(_.error(`Connector ${e} is not valid. Please fix the following errors:\n`),i.forEach(e=>{console.info(t.default.red(`- L${e.line}: ${e.message}`))})):_.error(`Connector ${e} is not valid. Please check the file for errors.`)},w=e=>{let t=[],n=(0,i.readdirSync)(e,{withFileTypes:!0});for(let r of n){let n=(0,o.join)(e,r.name);r.isDirectory()?t.push(...w(n)):r.name.endsWith(`.s1.yaml`)&&t.push(n)}return t};var T=class{async execute(e){let{watchMode:n,fileOrDir:r}=e,a=(0,c.default)(`Watching for changes...`),o=()=>{console.clear(),console.info(t.default.yellow(`Watch mode enabled. Press "q" to quit.
|
|
4
|
+
`))};if(r){try{(0,i.statSync)(r)}catch{_.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:e}=await Promise.resolve().then(()=>require(`./esm-BrK-ICga.cjs`)),n=await import(`readline`),i=n.createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let s=()=>{console.info(t.default.grey(`
|
|
5
|
+
|
|
6
|
+
Exiting watch mode...`)),c.close(),a.stop(),i.close(),process.exit(0)};o(),console.info(t.default.blue(`Running connector(s) validations...`)),await E(r),a.start();let c=e(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});c.on(`change`,async e=>{o(),a.stop(),console.info(t.default.blue(`File change detected. Running connector(s) validations...`)),await E(r),a.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&s()}),process.on(`SIGINT`,()=>{s()})}else await E(r),process.exit(0)}}};const E=async e=>{let t=(0,i.statSync)(e);if(t.isDirectory()){let t=(0,i.readdirSync)(e),n=t.filter(e=>e.endsWith(`.s1.yaml`));if(n.length===0){_.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let r=0,a=0;for(let t of n){let n=`${e}/${t}`,o=(0,i.statSync)(n);if(o.isFile()){let e=await D(n);e?r++:a++}}_.info(`Validation completed: ${r} valid, ${a} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await D(e):_.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},D=async e=>{let n=(0,s.loadConnector)(e),r=(0,s.validateYamlConnector)(n),i=r?.errors??[];if(r.success){let t=e.split(`/`).pop()||e;return _.success(`Connector ${t} is valid!\n`),!0}else if(i.length>0)return _.error(`Connector ${e} is not valid. Please fix the following errors:\n`),i.forEach(e=>{console.info(t.default.red(`- L${e.line}: ${e.message}`))}),console.info(`
|
|
7
|
+
`),!1;else return _.error(`Connector ${e} is not valid. Please check the file for errors.`),!1},O=()=>{try{let e=(0,l.fileURLToPath)(require(`url`).pathToFileURL(__filename).href),t=(0,o.dirname)(e),n=(0,o.join)(t,`..`,`package.json`),r=JSON.parse((0,i.readFileSync)(n,`utf8`));return r.version}catch{return`unknown`}};var k=class{constructor(e=new n.Command,t=O()){this.program=e,this.version=t,this.setupProgram(),this.registerCommands()}setupProgram(){this.program.name(`stackone`).description(`StackOne CLI`).version(this.version)}registerCommands(){let e=new x,r=new S,i=new T;this.program.configureOutput({writeOut:e=>process.stdout.write(e),writeErr:e=>process.stderr.write(e),outputError:(e,n)=>{n(t.default.red(e))}}),this.program.command(`init`).description(`Initialize & create a StackOne CLI configuration profile`).action(()=>{e.execute()}),this.program.command(`push`).option(`-p, --profile <label>`,`Configuration profile to use`).addArgument(new n.Argument(`<path>`,`Connector file or directory to push`)).description(`Push a connector to the StackOne registry`).action((e,t)=>{r.execute({profile:t.profile,fileOrDir:e})}),this.program.command(`validate`).option(`-w, --watch`,`Run in watch mode`).addArgument(new n.Argument(`<path>`,`Connector file or directory with connectors to validate`)).description(`Validate a StackOne connector`).action((e,t)=>{i.execute({watchMode:t.watch,fileOrDir:e})}),this.program.command(`version`).description(`Show version information`).action(()=>{console.info(`${t.default.greenBright(`StackOne`)} ${t.default.grey(`CLI`)} ${t.default.whiteBright(this.version)}`),process.exit(0)})}run(){this.program.parse(process.argv)}};Object.defineProperty(exports,`CLI`,{enumerable:!0,get:function(){return k}});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import e from"chalk";import{Argument as t,Command as n}from"commander";import r from"inquirer";import{existsSync as i,mkdirSync as a,readFileSync as o,readdirSync as s,statSync as c,writeFileSync as l}from"fs";import{homedir as u}from"os";import{basename as d,dirname as f,join as p}from"path";import{loadConnector as m,validateYamlConnector as h}from"@stackone/connect-sdk";import g from"ora";import{fileURLToPath as _}from"url";const v=p(u(),`.stackone`),y={profiles:{}},b=()=>{if(!i(v))return y;try{let e=o(v,`utf-8`);return JSON.parse(e)}catch{return y}},x=e=>{let t=b();return t.profiles[e]},S=e=>{let t=b();return!!t.profiles[e]},C=(e,t)=>{let n=b();n.profiles[e]=t;let r=p(u());i(r)||a(r,{recursive:!0}),l(v,JSON.stringify(n,null,2),`utf-8`)},w=()=>{let e=b();return Object.keys(e.profiles)};var T=class{static info(t){console.info(e.blue(`ℹ`),t)}static warn(t){console.info(e.yellow(`⚠`),t)}static error(t){console.info(e.red(`✗`),t)}static success(t){console.info(e.green(`✓`),t)}};const E=`https://api.stackone.com`,D=`https://api.stackone-dev.com`,O=`http://localhost:4000`;var k=class{async execute(){try{let{label:t}=await r.prompt([{type:`input`,name:`label`,message:`Profile label:`,validate:e=>!e||e.trim().length===0?`The profile label is required`:e.includes(` `)?`The profile label cannot contain spaces`:!0}]);if(S(t)){let{overwrite:e}=await r.prompt([{type:`confirm`,name:`overwrite`,message:`Configuration profile with name "${t}" already exists. Do you want to overwrite it?`,default:!1}]);e||(T.info(`Configuration profile initialization cancelled`),process.exit(0))}let{environment:n}=await r.prompt([{type:`list`,name:`environment`,message:`Environment:`,choices:[`production`,`staging`,`local`]}]),i;if(n===`production`)i=E;else if(n===`staging`)i=D;else{let{customUrl:e}=await r.prompt([{type:`input`,name:`customUrl`,message:`API URL:`,default:O,validate:e=>{if(!e||e.trim().length===0)return`API URL is required`;try{return new URL(e),!0}catch{return`Please enter a valid URL`}}}]);i=e}let{apiKey:a}=await r.prompt([{type:`password`,name:`apiKey`,message:`API Key:`,validate:e=>!e||e.trim().length===0?`API Key is required`:!0}]),o={label:t,environment:n,apiUrl:i,apiKey:a};C(t,o),console.info(e.green(`\n✓ Configuration profile "${t}" saved successfully`)),process.exit(0)}catch(e){e.isTtyError?T.error(`Prompt couldn't be rendered in the current environment`):T.error(`Failed to initialize configuration profile: ${e}`),process.exit(1)}}},A=class{async execute(e){let{profile:t,fileOrDir:n}=e;if(t||(T.error(`Profile is required. Use --profile <label> to specify a configuration.`),T.info(`Run "stackone init" to create a new configuration profile.`),process.exit(1)),!S(t)){T.error(`Configuration profile "${t}" not found.`),T.info(`Run "stackone init" to create a new configuration profile.`);let e=w();T.info(`Available profiles: ${e.join(`, `)||`none`}`),process.exit(1)}let r=x(t);r||(T.error(`Failed to load configuration profile "${t}".`),process.exit(1)),n||(T.error(`File or directory path is required.`),process.exit(1));try{c(n)}catch{T.error(`File or directory not found: ${n}`),process.exit(1)}let i=c(n);if(i.isDirectory()){let e=M(n),t=0;e.length===0?(T.error(`No .s1.yaml connector files found in the directory: ${n}.`),process.exit(1)):T.info(`Found ${e.length} connector(s) file(s). Processing...`);for(let n of e){console.info(`
|
|
2
|
+
`);let e=await this.uploadFile(n,r.apiUrl,r.apiKey);e&&t++}console.info(`
|
|
3
|
+
`),T.info(`Upload completed: ${t} of ${e.length} file(s) uploaded successfully.`),process.exit(t>0?0:1)}else n.endsWith(`.s1.yaml`)||(T.error(`Only .s1.yaml files are supported for upload.`),process.exit(1));let a=await this.uploadFile(n,r.apiUrl,r.apiKey);process.exit(a?0:1)}async uploadFile(t,n,r){try{console.info(e.blue(`📤 Uploading ${d(t)}...`));let i=j(t);if(!i)return!1;let a=d(t),o=new FormData,s=new Blob([i],{type:`application/x-yaml`});o.append(`file`,s,a);let c=Buffer.from(r).toString(`base64`),l=await fetch(`${n}/registry/connectors`,{method:`POST`,headers:{Authorization:`Basic ${c}`},body:o});if(!l.ok){let t=await l.text();return T.error(`Upload failed: ${l.status} - ${l.statusText}`),t&&console.error(e.red(t)),!1}let u=await l.json();return console.info(e.green(`✓ Successfully uploaded ${a} with connector "${u.provider}@${u.version}"`)),!0}catch(e){return T.error(`Failed to upload file: ${e}`),!1}}};const j=t=>{let n=m(t),r=h(n),i=r?.errors??[];if(r.success){let e=t.split(`/`).pop()||t;return T.success(`Connector ${e} is valid!`),n}else i.length>0?(T.error(`Connector ${t} is not valid. Please fix the following errors:\n`),i.forEach(t=>{console.info(e.red(`- L${t.line}: ${t.message}`))})):T.error(`Connector ${t} is not valid. Please check the file for errors.`)},M=e=>{let t=[],n=s(e,{withFileTypes:!0});for(let r of n){let n=p(e,r.name);r.isDirectory()?t.push(...M(n)):r.name.endsWith(`.s1.yaml`)&&t.push(n)}return t};var N=class{async execute(t){let{watchMode:n,fileOrDir:r}=t,i=g(`Watching for changes...`),a=()=>{console.clear(),console.info(e.yellow(`Watch mode enabled. Press "q" to quit.
|
|
4
|
+
`))};if(r){try{c(r)}catch{T.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:t}=await import(`./esm-D_hUWJ1V.js`),n=await import(`readline`),o=n.createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let s=()=>{console.info(e.grey(`
|
|
5
|
+
|
|
6
|
+
Exiting watch mode...`)),c.close(),i.stop(),o.close(),process.exit(0)};a(),console.info(e.blue(`Running connector(s) validations...`)),await P(r),i.start();let c=t(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});c.on(`change`,async t=>{a(),i.stop(),console.info(e.blue(`File change detected. Running connector(s) validations...`)),await P(r),i.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&s()}),process.on(`SIGINT`,()=>{s()})}else await P(r),process.exit(0)}}};const P=async e=>{let t=c(e);if(t.isDirectory()){let t=s(e),n=t.filter(e=>e.endsWith(`.s1.yaml`));if(n.length===0){T.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let r=0,i=0;for(let t of n){let n=`${e}/${t}`,a=c(n);if(a.isFile()){let e=await F(n);e?r++:i++}}T.info(`Validation completed: ${r} valid, ${i} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await F(e):T.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},F=async t=>{let n=m(t),r=h(n),i=r?.errors??[];if(r.success){let e=t.split(`/`).pop()||t;return T.success(`Connector ${e} is valid!\n`),!0}else if(i.length>0)return T.error(`Connector ${t} is not valid. Please fix the following errors:\n`),i.forEach(t=>{console.info(e.red(`- L${t.line}: ${t.message}`))}),console.info(`
|
|
7
|
+
`),!1;else return T.error(`Connector ${t} is not valid. Please check the file for errors.`),!1},I=()=>{try{let e=_(import.meta.url),t=f(e),n=p(t,`..`,`package.json`),r=JSON.parse(o(n,`utf8`));return r.version}catch{return`unknown`}};var L=class{constructor(e=new n,t=I()){this.program=e,this.version=t,this.setupProgram(),this.registerCommands()}setupProgram(){this.program.name(`stackone`).description(`StackOne CLI`).version(this.version)}registerCommands(){let n=new k,r=new A,i=new N;this.program.configureOutput({writeOut:e=>process.stdout.write(e),writeErr:e=>process.stderr.write(e),outputError:(t,n)=>{n(e.red(t))}}),this.program.command(`init`).description(`Initialize & create a StackOne CLI configuration profile`).action(()=>{n.execute()}),this.program.command(`push`).option(`-p, --profile <label>`,`Configuration profile to use`).addArgument(new t(`<path>`,`Connector file or directory to push`)).description(`Push a connector to the StackOne registry`).action((e,t)=>{r.execute({profile:t.profile,fileOrDir:e})}),this.program.command(`validate`).option(`-w, --watch`,`Run in watch mode`).addArgument(new t(`<path>`,`Connector file or directory with connectors to validate`)).description(`Validate a StackOne connector`).action((e,t)=>{i.execute({watchMode:t.watch,fileOrDir:e})}),this.program.command(`version`).description(`Show version information`).action(()=>{console.info(`${e.greenBright(`StackOne`)} ${e.grey(`CLI`)} ${e.whiteBright(this.version)}`),process.exit(0)})}run(){this.program.parse(process.argv)}};export{L as CLI};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`fs`)),n=e.__toESM(require(`path`)),r=e.__toESM(require(`fs/promises`)),i=e.__toESM(require(`events`)),a=e.__toESM(require(`node:fs/promises`)),o=e.__toESM(require(`node:stream`)),s=e.__toESM(require(`node:path`)),c=e.__toESM(require(`os`)),l={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},u={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:l.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(u);const d=`READDIRP_RECURSIVE_ERROR`,f=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,d]),p=[l.DIR_TYPE,l.EVERYTHING_TYPE,l.FILE_DIR_TYPE,l.FILE_TYPE],ee=new Set([l.DIR_TYPE,l.EVERYTHING_TYPE,l.FILE_DIR_TYPE]),m=new Set([l.EVERYTHING_TYPE,l.FILE_DIR_TYPE,l.FILE_TYPE]),te=e=>f.has(e.code),ne=process.platform===`win32`,h=e=>!0,g=e=>{if(e===void 0)return h;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return h};var _=class extends o.Readable{constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...u,...e},{root:n,type:r}=t;this._fileFilter=g(t.fileFilter),this._directoryFilter=g(t.directoryFilter);let i=t.lstat?a.lstat:a.stat;ne?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth??u.depth,this._wantsDir=r?ee.has(r):!1,this._wantsFile=r?m.has(r):!1,this._wantsEverything=r===l.EVERYTHING_TYPE,this._root=(0,s.resolve)(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await(0,a.readdir)(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=(0,s.resolve)((0,s.join)(t,r));n={path:(0,s.relative)(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){te(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await(0,a.realpath)(t),n=await(0,a.lstat)(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===s.sep){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=d,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function v(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=l.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!p.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${p.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new _(t)}const re=`data`,y=`end`,ie=`close`,b=()=>{},x=process.platform,S=x===`win32`,C=x===`darwin`,w=x===`linux`,T=x===`freebsd`,E=(0,c.type)()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,ae=`watch`,oe={lstat:r.lstat,stat:r.stat},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,se=[k,A,j],ce=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),le=e=>ce.has(n.extname(e).slice(1).toLowerCase()),M=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},N=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ue=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},P=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},F=e=>e instanceof Set?e.size===0:!e,I=new Map;function L(e,r,i,a,o){let s=(t,r)=>{i(e),o(t,r,{watchedPath:e}),r&&e!==r&&R(n.resolve(e,r),k,n.join(e,r))};try{return(0,t.watch)(e,{persistent:r.persistent},s)}catch(e){a(e);return}}const R=(e,t,n,r,i)=>{let a=I.get(e);a&&M(a[t],e=>{e(n,r,i)})},z=(e,t,n,i)=>{let{listener:a,errHandler:o,rawEmitter:s}=i,c=I.get(t),l;if(!n.persistent)return l=L(e,n,a,o,s),l?l.close.bind(l):void 0;if(c)N(c,k,a),N(c,A,o),N(c,j,s);else{if(l=L(e,n,R.bind(null,t,k),o,R.bind(null,t,j)),!l)return;l.on(O.ERROR,async n=>{let i=R.bind(null,t,A);if(c&&(c.watcherUnusable=!0),S&&n.code===`EPERM`)try{let t=await(0,r.open)(e,`r`);await t.close(),i(n)}catch{}else i(n)}),c={listeners:a,errHandlers:o,rawEmitters:s,watcher:l},I.set(t,c)}return()=>{P(c,k,a),P(c,A,o),P(c,j,s),F(c.listeners)&&(c.watcher.close(),I.delete(t),se.forEach(ue(c)),c.watcher=void 0,Object.freeze(c))}},B=new Map,V=(e,n,r,i)=>{let{listener:a,rawEmitter:o}=i,s=B.get(n),c=s&&s.options;return c&&(c.persistent<r.persistent||c.interval>r.interval)&&((0,t.unwatchFile)(n),s=void 0),s?(N(s,k,a),N(s,j,o)):(s={listeners:a,rawEmitters:o,options:r,watcher:(0,t.watchFile)(n,r,(t,r)=>{M(s.rawEmitters,e=>{e(O.CHANGE,n,{curr:t,prev:r})});let i=t.mtimeMs;(t.size!==r.size||i>r.mtimeMs||i===0)&&M(s.listeners,n=>n(e,t))})},B.set(n,s)),()=>{P(s,k,a),P(s,j,o),F(s.listeners)&&(B.delete(n),(0,t.unwatchFile)(n),s.options=s.watcher=void 0,Object.freeze(s))}};var H=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let r=this.fsw.options,i=n.dirname(e),a=n.basename(e),o=this.fsw._getWatchedDir(i);o.add(a);let s=n.resolve(e),c={persistent:r.persistent};t||=b;let l;if(r.usePolling){let n=r.interval!==r.binaryInterval;c.interval=n&&le(a)?r.binaryInterval:r.interval,l=V(e,s,c,{listener:t,rawEmitter:this.fsw._emitRaw})}else l=z(e,s,c,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(e,t,i){if(this.fsw.closed)return;let a=n.dirname(e),o=n.basename(e),s=this.fsw._getWatchedDir(a),c=t;if(s.has(o))return;let l=async(t,n)=>{if(this.fsw._throttle(ae,e,5)){if(!n||n.mtimeMs===0)try{let n=await(0,r.stat)(e);if(this.fsw.closed)return;let i=n.atimeMs,a=n.mtimeMs;if((!i||i<=a||a!==c.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(C||w||T)&&c.ino!==n.ino){this.fsw._closeFile(t),c=n;let r=this._watchWithNodeFs(e,l);r&&this.fsw._addPathCloser(t,r)}else c=n}catch{this.fsw._remove(a,o)}else if(s.has(o)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==c.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),c=n}}},u=this._watchWithNodeFs(e,l);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return u}async _handleSymlink(e,t,n,i){if(this.fsw.closed)return;let a=e.fullPath,o=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await(0,r.realpath)(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(o.has(i)?this.fsw._symlinkPaths.get(a)!==t&&(this.fsw._symlinkPaths.set(a,t),this.fsw._emit(O.CHANGE,n,e.stats)):(o.add(i),this.fsw._symlinkPaths.set(a,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(a))return!0;this.fsw._symlinkPaths.set(a,!0)}_handleRead(e,t,r,i,a,o,s){if(e=n.join(e,``),s=this.fsw._throttle(`readdir`,e,1e3),!s)return;let c=this.fsw._getWatchedDir(r.path),l=new Set,u=this.fsw._readdirp(e,{fileFilter:e=>r.filterPath(e),directoryFilter:e=>r.filterDir(e)});if(u)return u.on(re,async s=>{if(this.fsw.closed){u=void 0;return}let d=s.path,f=n.join(e,d);if(l.add(d),!(s.stats.isSymbolicLink()&&await this._handleSymlink(s,e,f,d))){if(this.fsw.closed){u=void 0;return}(d===i||!i&&!c.has(d))&&(this.fsw._incrReadyCount(),f=n.join(a,n.relative(a,f)),this._addToNodeFs(f,t,r,o+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,n)=>{if(!u)return n();u.once(y,()=>{if(this.fsw.closed){u=void 0;return}let n=s?s.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),u=void 0,n&&this._handleRead(e,!1,r,i,a,o,s)})})}async _handleDir(e,t,r,i,a,o,s){let c=this.fsw._getWatchedDir(n.dirname(e)),l=c.has(n.basename(e));!(r&&this.fsw.options.ignoreInitial)&&!a&&!l&&this.fsw._emit(O.ADD_DIR,e,t),c.add(n.basename(e)),this.fsw._getWatchedDir(e);let u,d,f=this.fsw.options.depth;if((f==null||i<=f)&&!this.fsw._symlinkPaths.has(s)){if(!a&&(await this._handleRead(e,r,o,a,e,i,u),this.fsw.closed))return;d=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,o,a,e,i,u)})}return d}async _addToNodeFs(e,t,i,a,o){let s=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return s(),!1;let c=this.fsw._getWatchHelpers(e);i&&(c.filterPath=e=>i.filterPath(e),c.filterDir=e=>i.filterDir(e));try{let i=await oe[c.statMethod](c.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(c.watchPath,i))return s(),!1;let l=this.fsw.options.followSymlinks,u;if(i.isDirectory()){let s=n.resolve(e),d=l?await(0,r.realpath)(e):e;if(this.fsw.closed||(u=await this._handleDir(c.watchPath,i,t,a,o,c,d),this.fsw.closed))return;s!==d&&d!==void 0&&this.fsw._symlinkPaths.set(s,d)}else if(i.isSymbolicLink()){let o=l?await(0,r.realpath)(e):e;if(this.fsw.closed)return;let s=n.dirname(c.watchPath);if(this.fsw._getWatchedDir(s).add(c.watchPath),this.fsw._emit(O.ADD,c.watchPath,i),u=await this._handleDir(s,i,t,a,e,c,o),this.fsw.closed)return;o!==void 0&&this.fsw._symlinkPaths.set(n.resolve(e),o)}else u=this._handleFile(c.watchPath,i,t);return s(),u&&this.fsw._addPathCloser(e,u),!1}catch(t){if(this.fsw._handleError(t))return s(),e}}};const U=`/`,de=`//`,W=`.`,fe=`..`,pe=`string`,me=/\\/g,G=/\/\//,he=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,ge=/^\.[/\\]/;function K(e){return Array.isArray(e)?e:[e]}const q=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function _e(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let r=n.relative(e.path,t);return r?!r.startsWith(`..`)&&!n.isAbsolute(r):!1}return!1}:()=>!1}function ve(e){if(typeof e!=`string`)throw Error(`string expected`);e=n.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let r=/\/\//;for(;e.match(r);)e=e.replace(r,`/`);return t&&(e=`/`+e),e}function J(e,t,n){let r=ve(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function ye(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=K(e),r=n.map(e=>_e(e));return t==null?(e,t)=>J(r,e,t):J(r,t)}const Y=e=>{let t=K(e).flat();if(!t.every(e=>typeof e===pe))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Z)},X=e=>{let t=e.replace(me,U),n=!1;for(t.startsWith(de)&&(n=!0);t.match(G);)t=t.replace(G,U);return n&&(t=U+t),t},Z=e=>X(n.normalize(X(e))),Q=(e=``)=>t=>typeof t==`string`?Z(n.isAbsolute(t)?t:n.join(e,t)):t,be=(e,t)=>n.isAbsolute(e)?e:n.join(t,e),xe=Object.freeze(new Set);var Se=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==W&&e!==fe&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let i=this.path;try{await(0,r.readdir)(i)}catch{this._removeWatcher&&this._removeWatcher(n.dirname(i),n.basename(i))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=b,this.items=xe,Object.freeze(this)}};const Ce=`stat`,$=`lstat`;var we=class{constructor(e,t,r){this.fsw=r;let i=e;this.path=e=e.replace(ge,``),this.watchPath=i,this.fullWatchPath=n.resolve(i),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Ce:$}entryPath(e){return n.join(this.watchPath,n.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Te=class extends i.EventEmitter{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?K(e.ignored):K([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};E&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=b,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new H(this),Object.freeze(r)}_addIgnoredPath(e){if(q(e)){for(let t of this._ignoredPaths)if(q(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)q(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,r){let{cwd:i}=this.options;this.closed=!1,this._closePromise=void 0;let a=Y(e);return i&&(a=a.map(e=>{let t=be(e,i);return t})),a.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=a.length,Promise.all(a.map(async e=>{let n=await this._nodeFsHandler._addToNodeFs(e,!r,void 0,0,t);return n&&this._emitReady(),n})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(n.dirname(e),n.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Y(e),{cwd:r}=this.options;return t.forEach(e=>{!n.isAbsolute(e)&&!this._closers.has(e)&&(r&&(e=n.join(r,e)),e=n.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,r)=>{let i=this.options.cwd?n.relative(this.options.cwd,r):r,a=i||W;e[a]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,i){if(this.closed)return;let a=this.options;S&&(t=n.normalize(t)),a.cwd&&(t=n.relative(a.cwd,t));let o=[t];i!=null&&o.push(i);let s=a.awaitWriteFinish,c;if(s&&(c=this._pendingWrites.get(t)))return c.lastChange=new Date,this;if(a.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...o]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof a.atomic==`number`?a.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(s&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,o[0]=t,this.emitWithAll(e,o)):n&&(o.length>1?o[1]=n:o.push(n),this.emitWithAll(e,o))};return this._awaitWriteFinish(t,s.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(a.alwaysStat&&i===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=a.cwd?n.join(a.cwd,t):t,i;try{i=await(0,r.stat)(e)}catch{}if(!i||this.closed)return;o.push(i)}return this.emitWithAll(e,o),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,r,i,a){let o=this.options.awaitWriteFinish;if(typeof o!=`object`)return;let s=o.pollInterval,c,l=e;this.options.cwd&&!n.isAbsolute(e)&&(l=n.join(this.options.cwd,e));let u=new Date,d=this._pendingWrites;function f(n){(0,t.stat)(l,(t,i)=>{if(t||!d.has(e)){t&&t.code!==`ENOENT`&&a(t);return}let o=Number(new Date);n&&i.size!==n.size&&(d.get(e).lastChange=o);let l=d.get(e),u=o-l.lastChange;u>=r?(d.delete(e),a(void 0,i)):c=setTimeout(f,s,i)})}d.has(e)||(d.set(e,{lastChange:u,cancelWait:()=>(d.delete(e),clearTimeout(c),i)}),c=setTimeout(f,s))}_isIgnored(e,t){if(this.options.atomic&&he.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map(Q(e)),r=[...this._ignoredPaths],i=[...r.map(Q(e)),...n];this._userIgnored=ye(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new we(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=n.resolve(e);return this._watched.has(t)||this._watched.set(t,new Se(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,r){let i=n.join(e,t),a=n.resolve(i);if(r??=this._watched.has(i)||this._watched.has(a),!this._throttle(`remove`,i,100))return;!r&&this._watched.size===1&&this.add(e,t,!0);let o=this._getWatchedDir(i),s=o.getChildren();s.forEach(e=>this._remove(i,e));let c=this._getWatchedDir(e),l=c.has(t);c.remove(t),this._symlinkPaths.has(a)&&this._symlinkPaths.delete(a);let u=i;if(this.options.cwd&&(u=n.relative(this.options.cwd,i)),this.options.awaitWriteFinish&&this._pendingWrites.has(u)){let e=this._pendingWrites.get(u).cancelWait();if(e===D.ADD)return}this._watched.delete(i),this._watched.delete(a);let d=r?D.UNLINK_DIR:D.UNLINK;l&&!this._isIgnored(i)&&this._emit(d,i),this._closePath(i)}_closePath(e){this._closeFile(e);let t=n.dirname(e);this._getWatchedDir(t).remove(n.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=v(e,n);return this._streams.add(r),r.once(ie,()=>{r=void 0}),r.once(y,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Ee(e,t={}){let n=new Te(t);return n.add(e),n}exports.watch=Ee;
|
|
1
|
+
const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`fs`)),n=e.__toESM(require(`os`)),r=e.__toESM(require(`path`)),i=e.__toESM(require(`fs/promises`)),a=e.__toESM(require(`events`)),o=e.__toESM(require(`node:fs/promises`)),s=e.__toESM(require(`node:stream`)),c=e.__toESM(require(`node:path`)),l={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},u={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:l.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(u);const d=`READDIRP_RECURSIVE_ERROR`,f=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,d]),p=[l.DIR_TYPE,l.EVERYTHING_TYPE,l.FILE_DIR_TYPE,l.FILE_TYPE],ee=new Set([l.DIR_TYPE,l.EVERYTHING_TYPE,l.FILE_DIR_TYPE]),m=new Set([l.EVERYTHING_TYPE,l.FILE_DIR_TYPE,l.FILE_TYPE]),te=e=>f.has(e.code),ne=process.platform===`win32`,h=e=>!0,g=e=>{if(e===void 0)return h;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return h};var _=class extends s.Readable{constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...u,...e},{root:n,type:r}=t;this._fileFilter=g(t.fileFilter),this._directoryFilter=g(t.directoryFilter);let i=t.lstat?o.lstat:o.stat;ne?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth??u.depth,this._wantsDir=r?ee.has(r):!1,this._wantsFile=r?m.has(r):!1,this._wantsEverything=r===l.EVERYTHING_TYPE,this._root=(0,c.resolve)(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await(0,o.readdir)(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=(0,c.resolve)((0,c.join)(t,r));n={path:(0,c.relative)(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){te(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await(0,o.realpath)(t),n=await(0,o.lstat)(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===c.sep){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=d,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function v(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=l.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!p.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${p.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new _(t)}const re=`data`,y=`end`,ie=`close`,b=()=>{},x=process.platform,S=x===`win32`,C=x===`darwin`,w=x===`linux`,T=x===`freebsd`,E=(0,n.type)()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,ae=`watch`,oe={lstat:i.lstat,stat:i.stat},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,se=[k,A,j],ce=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),le=e=>ce.has(r.extname(e).slice(1).toLowerCase()),M=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},N=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ue=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},P=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},F=e=>e instanceof Set?e.size===0:!e,I=new Map;function L(e,n,i,a,o){let s=(t,n)=>{i(e),o(t,n,{watchedPath:e}),n&&e!==n&&R(r.resolve(e,n),k,r.join(e,n))};try{return(0,t.watch)(e,{persistent:n.persistent},s)}catch(e){a(e);return}}const R=(e,t,n,r,i)=>{let a=I.get(e);a&&M(a[t],e=>{e(n,r,i)})},z=(e,t,n,r)=>{let{listener:a,errHandler:o,rawEmitter:s}=r,c=I.get(t),l;if(!n.persistent)return l=L(e,n,a,o,s),l?l.close.bind(l):void 0;if(c)N(c,k,a),N(c,A,o),N(c,j,s);else{if(l=L(e,n,R.bind(null,t,k),o,R.bind(null,t,j)),!l)return;l.on(O.ERROR,async n=>{let r=R.bind(null,t,A);if(c&&(c.watcherUnusable=!0),S&&n.code===`EPERM`)try{let t=await(0,i.open)(e,`r`);await t.close(),r(n)}catch{}else r(n)}),c={listeners:a,errHandlers:o,rawEmitters:s,watcher:l},I.set(t,c)}return()=>{P(c,k,a),P(c,A,o),P(c,j,s),F(c.listeners)&&(c.watcher.close(),I.delete(t),se.forEach(ue(c)),c.watcher=void 0,Object.freeze(c))}},B=new Map,V=(e,n,r,i)=>{let{listener:a,rawEmitter:o}=i,s=B.get(n),c=s&&s.options;return c&&(c.persistent<r.persistent||c.interval>r.interval)&&((0,t.unwatchFile)(n),s=void 0),s?(N(s,k,a),N(s,j,o)):(s={listeners:a,rawEmitters:o,options:r,watcher:(0,t.watchFile)(n,r,(t,r)=>{M(s.rawEmitters,e=>{e(O.CHANGE,n,{curr:t,prev:r})});let i=t.mtimeMs;(t.size!==r.size||i>r.mtimeMs||i===0)&&M(s.listeners,n=>n(e,t))})},B.set(n,s)),()=>{P(s,k,a),P(s,j,o),F(s.listeners)&&(B.delete(n),(0,t.unwatchFile)(n),s.options=s.watcher=void 0,Object.freeze(s))}};var H=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,i=r.dirname(e),a=r.basename(e),o=this.fsw._getWatchedDir(i);o.add(a);let s=r.resolve(e),c={persistent:n.persistent};t||=b;let l;if(n.usePolling){let r=n.interval!==n.binaryInterval;c.interval=r&&le(a)?n.binaryInterval:n.interval,l=V(e,s,c,{listener:t,rawEmitter:this.fsw._emitRaw})}else l=z(e,s,c,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(e,t,n){if(this.fsw.closed)return;let a=r.dirname(e),o=r.basename(e),s=this.fsw._getWatchedDir(a),c=t;if(s.has(o))return;let l=async(t,n)=>{if(this.fsw._throttle(ae,e,5)){if(!n||n.mtimeMs===0)try{let n=await(0,i.stat)(e);if(this.fsw.closed)return;let r=n.atimeMs,a=n.mtimeMs;if((!r||r<=a||a!==c.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(C||w||T)&&c.ino!==n.ino){this.fsw._closeFile(t),c=n;let r=this._watchWithNodeFs(e,l);r&&this.fsw._addPathCloser(t,r)}else c=n}catch{this.fsw._remove(a,o)}else if(s.has(o)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==c.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),c=n}}},u=this._watchWithNodeFs(e,l);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return u}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let a=e.fullPath,o=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await(0,i.realpath)(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(o.has(r)?this.fsw._symlinkPaths.get(a)!==t&&(this.fsw._symlinkPaths.set(a,t),this.fsw._emit(O.CHANGE,n,e.stats)):(o.add(r),this.fsw._symlinkPaths.set(a,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(a))return!0;this.fsw._symlinkPaths.set(a,!0)}_handleRead(e,t,n,i,a,o,s){if(e=r.join(e,``),s=this.fsw._throttle(`readdir`,e,1e3),!s)return;let c=this.fsw._getWatchedDir(n.path),l=new Set,u=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(u)return u.on(re,async s=>{if(this.fsw.closed){u=void 0;return}let d=s.path,f=r.join(e,d);if(l.add(d),!(s.stats.isSymbolicLink()&&await this._handleSymlink(s,e,f,d))){if(this.fsw.closed){u=void 0;return}(d===i||!i&&!c.has(d))&&(this.fsw._incrReadyCount(),f=r.join(a,r.relative(a,f)),this._addToNodeFs(f,t,n,o+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,r)=>{if(!u)return r();u.once(y,()=>{if(this.fsw.closed){u=void 0;return}let r=s?s.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),u=void 0,r&&this._handleRead(e,!1,n,i,a,o,s)})})}async _handleDir(e,t,n,i,a,o,s){let c=this.fsw._getWatchedDir(r.dirname(e)),l=c.has(r.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!a&&!l&&this.fsw._emit(O.ADD_DIR,e,t),c.add(r.basename(e)),this.fsw._getWatchedDir(e);let u,d,f=this.fsw.options.depth;if((f==null||i<=f)&&!this.fsw._symlinkPaths.has(s)){if(!a&&(await this._handleRead(e,n,o,a,e,i,u),this.fsw.closed))return;d=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,o,a,e,i,u)})}return d}async _addToNodeFs(e,t,n,a,o){let s=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return s(),!1;let c=this.fsw._getWatchHelpers(e);n&&(c.filterPath=e=>n.filterPath(e),c.filterDir=e=>n.filterDir(e));try{let n=await oe[c.statMethod](c.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(c.watchPath,n))return s(),!1;let l=this.fsw.options.followSymlinks,u;if(n.isDirectory()){let s=r.resolve(e),d=l?await(0,i.realpath)(e):e;if(this.fsw.closed||(u=await this._handleDir(c.watchPath,n,t,a,o,c,d),this.fsw.closed))return;s!==d&&d!==void 0&&this.fsw._symlinkPaths.set(s,d)}else if(n.isSymbolicLink()){let o=l?await(0,i.realpath)(e):e;if(this.fsw.closed)return;let s=r.dirname(c.watchPath);if(this.fsw._getWatchedDir(s).add(c.watchPath),this.fsw._emit(O.ADD,c.watchPath,n),u=await this._handleDir(s,n,t,a,e,c,o),this.fsw.closed)return;o!==void 0&&this.fsw._symlinkPaths.set(r.resolve(e),o)}else u=this._handleFile(c.watchPath,n,t);return s(),u&&this.fsw._addPathCloser(e,u),!1}catch(t){if(this.fsw._handleError(t))return s(),e}}};const U=`/`,de=`//`,W=`.`,fe=`..`,pe=`string`,me=/\\/g,G=/\/\//,he=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,ge=/^\.[/\\]/;function K(e){return Array.isArray(e)?e:[e]}const q=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function _e(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=r.relative(e.path,t);return n?!n.startsWith(`..`)&&!r.isAbsolute(n):!1}return!1}:()=>!1}function ve(e){if(typeof e!=`string`)throw Error(`string expected`);e=r.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let n=/\/\//;for(;e.match(n);)e=e.replace(n,`/`);return t&&(e=`/`+e),e}function J(e,t,n){let r=ve(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function ye(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=K(e),r=n.map(e=>_e(e));return t==null?(e,t)=>J(r,e,t):J(r,t)}const Y=e=>{let t=K(e).flat();if(!t.every(e=>typeof e===pe))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Z)},X=e=>{let t=e.replace(me,U),n=!1;for(t.startsWith(de)&&(n=!0);t.match(G);)t=t.replace(G,U);return n&&(t=U+t),t},Z=e=>X(r.normalize(X(e))),Q=(e=``)=>t=>typeof t==`string`?Z(r.isAbsolute(t)?t:r.join(e,t)):t,be=(e,t)=>r.isAbsolute(e)?e:r.join(t,e),xe=Object.freeze(new Set);var Se=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==W&&e!==fe&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await(0,i.readdir)(n)}catch{this._removeWatcher&&this._removeWatcher(r.dirname(n),r.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=b,this.items=xe,Object.freeze(this)}};const Ce=`stat`,$=`lstat`;var we=class{constructor(e,t,n){this.fsw=n;let i=e;this.path=e=e.replace(ge,``),this.watchPath=i,this.fullWatchPath=r.resolve(i),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Ce:$}entryPath(e){return r.join(this.watchPath,r.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Te=class extends a.EventEmitter{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?K(e.ignored):K([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};E&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=b,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new H(this),Object.freeze(r)}_addIgnoredPath(e){if(q(e)){for(let t of this._ignoredPaths)if(q(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)q(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:i}=this.options;this.closed=!1,this._closePromise=void 0;let a=Y(e);return i&&(a=a.map(e=>{let t=be(e,i);return t})),a.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=a.length,Promise.all(a.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(r.dirname(e),r.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Y(e),{cwd:n}=this.options;return t.forEach(e=>{!r.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=r.join(n,e)),e=r.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let i=this.options.cwd?r.relative(this.options.cwd,n):n,a=i||W;e[a]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let a=this.options;S&&(t=r.normalize(t)),a.cwd&&(t=r.relative(a.cwd,t));let o=[t];n!=null&&o.push(n);let s=a.awaitWriteFinish,c;if(s&&(c=this._pendingWrites.get(t)))return c.lastChange=new Date,this;if(a.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...o]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof a.atomic==`number`?a.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(s&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,o[0]=t,this.emitWithAll(e,o)):n&&(o.length>1?o[1]=n:o.push(n),this.emitWithAll(e,o))};return this._awaitWriteFinish(t,s.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(a.alwaysStat&&n===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=a.cwd?r.join(a.cwd,t):t,n;try{n=await(0,i.stat)(e)}catch{}if(!n||this.closed)return;o.push(n)}return this.emitWithAll(e,o),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,n,i,a){let o=this.options.awaitWriteFinish;if(typeof o!=`object`)return;let s=o.pollInterval,c,l=e;this.options.cwd&&!r.isAbsolute(e)&&(l=r.join(this.options.cwd,e));let u=new Date,d=this._pendingWrites;function f(r){(0,t.stat)(l,(t,i)=>{if(t||!d.has(e)){t&&t.code!==`ENOENT`&&a(t);return}let o=Number(new Date);r&&i.size!==r.size&&(d.get(e).lastChange=o);let l=d.get(e),u=o-l.lastChange;u>=n?(d.delete(e),a(void 0,i)):c=setTimeout(f,s,i)})}d.has(e)||(d.set(e,{lastChange:u,cancelWait:()=>(d.delete(e),clearTimeout(c),i)}),c=setTimeout(f,s))}_isIgnored(e,t){if(this.options.atomic&&he.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map(Q(e)),r=[...this._ignoredPaths],i=[...r.map(Q(e)),...n];this._userIgnored=ye(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new we(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=r.resolve(e);return this._watched.has(t)||this._watched.set(t,new Se(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let i=r.join(e,t),a=r.resolve(i);if(n??=this._watched.has(i)||this._watched.has(a),!this._throttle(`remove`,i,100))return;!n&&this._watched.size===1&&this.add(e,t,!0);let o=this._getWatchedDir(i),s=o.getChildren();s.forEach(e=>this._remove(i,e));let c=this._getWatchedDir(e),l=c.has(t);c.remove(t),this._symlinkPaths.has(a)&&this._symlinkPaths.delete(a);let u=i;if(this.options.cwd&&(u=r.relative(this.options.cwd,i)),this.options.awaitWriteFinish&&this._pendingWrites.has(u)){let e=this._pendingWrites.get(u).cancelWait();if(e===D.ADD)return}this._watched.delete(i),this._watched.delete(a);let d=n?D.UNLINK_DIR:D.UNLINK;l&&!this._isIgnored(i)&&this._emit(d,i),this._closePath(i)}_closePath(e){this._closeFile(e);let t=r.dirname(e);this._getWatchedDir(t).remove(r.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=v(e,n);return this._streams.add(r),r.once(ie,()=>{r=void 0}),r.once(y,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Ee(e,t={}){let n=new Te(t);return n.add(e),n}exports.watch=Ee;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stat as e,unwatchFile as t,watch as n,watchFile as r}from"fs";import*as i from"path";import{lstat as a,open as o,readdir as s,realpath as c,stat as l}from"fs/promises";import{EventEmitter as u}from"events";import{lstat as d,readdir as f,realpath as ee,stat as te}from"node:fs/promises";import{Readable as ne}from"node:stream";import{join as re,relative as ie,resolve as p,sep as m}from"node:path";import{type as ae}from"os";const h={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},g={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:h.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(g);const _=`READDIRP_RECURSIVE_ERROR`,oe=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,_]),v=[h.DIR_TYPE,h.EVERYTHING_TYPE,h.FILE_DIR_TYPE,h.FILE_TYPE],se=new Set([h.DIR_TYPE,h.EVERYTHING_TYPE,h.FILE_DIR_TYPE]),ce=new Set([h.EVERYTHING_TYPE,h.FILE_DIR_TYPE,h.FILE_TYPE]),y=e=>oe.has(e.code),b=process.platform===`win32`,x=e=>!0,S=e=>{if(e===void 0)return x;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return x};var le=class extends ne{constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...g,...e},{root:n,type:r}=t;this._fileFilter=S(t.fileFilter),this._directoryFilter=S(t.directoryFilter);let i=t.lstat?d:te;b?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth??g.depth,this._wantsDir=r?se.has(r):!1,this._wantsFile=r?ce.has(r):!1,this._wantsEverything=r===h.EVERYTHING_TYPE,this._root=p(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await f(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=p(re(t,r));n={path:ie(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){y(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await ee(t),n=await d(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===m){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=_,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function ue(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=h.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!v.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${v.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new le(t)}const de=`data`,C=`end`,fe=`close`,w=()=>{},T=process.platform,E=T===`win32`,pe=T===`darwin`,me=T===`linux`,he=T===`freebsd`,ge=ae()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,_e=`watch`,ve={lstat:a,stat:l},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,M=[k,A,j],N=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),P=e=>N.has(i.extname(e).slice(1).toLowerCase()),F=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},I=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ye=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},L=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},R=e=>e instanceof Set?e.size===0:!e,z=new Map;function B(e,t,r,a,o){let s=(t,n)=>{r(e),o(t,n,{watchedPath:e}),n&&e!==n&&V(i.resolve(e,n),k,i.join(e,n))};try{return n(e,{persistent:t.persistent},s)}catch(e){a(e);return}}const V=(e,t,n,r,i)=>{let a=z.get(e);a&&F(a[t],e=>{e(n,r,i)})},be=(e,t,n,r)=>{let{listener:i,errHandler:a,rawEmitter:s}=r,c=z.get(t),l;if(!n.persistent)return l=B(e,n,i,a,s),l?l.close.bind(l):void 0;if(c)I(c,k,i),I(c,A,a),I(c,j,s);else{if(l=B(e,n,V.bind(null,t,k),a,V.bind(null,t,j)),!l)return;l.on(O.ERROR,async n=>{let r=V.bind(null,t,A);if(c&&(c.watcherUnusable=!0),E&&n.code===`EPERM`)try{let t=await o(e,`r`);await t.close(),r(n)}catch{}else r(n)}),c={listeners:i,errHandlers:a,rawEmitters:s,watcher:l},z.set(t,c)}return()=>{L(c,k,i),L(c,A,a),L(c,j,s),R(c.listeners)&&(c.watcher.close(),z.delete(t),M.forEach(ye(c)),c.watcher=void 0,Object.freeze(c))}},H=new Map,xe=(e,n,i,a)=>{let{listener:o,rawEmitter:s}=a,c=H.get(n),l=c&&c.options;return l&&(l.persistent<i.persistent||l.interval>i.interval)&&(t(n),c=void 0),c?(I(c,k,o),I(c,j,s)):(c={listeners:o,rawEmitters:s,options:i,watcher:r(n,i,(t,r)=>{F(c.rawEmitters,e=>{e(O.CHANGE,n,{curr:t,prev:r})});let i=t.mtimeMs;(t.size!==r.size||i>r.mtimeMs||i===0)&&F(c.listeners,n=>n(e,t))})},H.set(n,c)),()=>{L(c,k,o),L(c,j,s),R(c.listeners)&&(H.delete(n),t(n),c.options=c.watcher=void 0,Object.freeze(c))}};var Se=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,r=i.dirname(e),a=i.basename(e),o=this.fsw._getWatchedDir(r);o.add(a);let s=i.resolve(e),c={persistent:n.persistent};t||=w;let l;if(n.usePolling){let r=n.interval!==n.binaryInterval;c.interval=r&&P(a)?n.binaryInterval:n.interval,l=xe(e,s,c,{listener:t,rawEmitter:this.fsw._emitRaw})}else l=be(e,s,c,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(e,t,n){if(this.fsw.closed)return;let r=i.dirname(e),a=i.basename(e),o=this.fsw._getWatchedDir(r),s=t;if(o.has(a))return;let c=async(t,n)=>{if(this.fsw._throttle(_e,e,5)){if(!n||n.mtimeMs===0)try{let n=await l(e);if(this.fsw.closed)return;let r=n.atimeMs,i=n.mtimeMs;if((!r||r<=i||i!==s.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(pe||me||he)&&s.ino!==n.ino){this.fsw._closeFile(t),s=n;let r=this._watchWithNodeFs(e,c);r&&this.fsw._addPathCloser(t,r)}else s=n}catch{this.fsw._remove(r,a)}else if(o.has(a)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==s.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),s=n}}},u=this._watchWithNodeFs(e,c);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return u}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let i=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await c(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(a.has(r)?this.fsw._symlinkPaths.get(i)!==t&&(this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.CHANGE,n,e.stats)):(a.add(r),this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(i))return!0;this.fsw._symlinkPaths.set(i,!0)}_handleRead(e,t,n,r,a,o,s){if(e=i.join(e,``),s=this.fsw._throttle(`readdir`,e,1e3),!s)return;let c=this.fsw._getWatchedDir(n.path),l=new Set,u=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(u)return u.on(de,async s=>{if(this.fsw.closed){u=void 0;return}let d=s.path,f=i.join(e,d);if(l.add(d),!(s.stats.isSymbolicLink()&&await this._handleSymlink(s,e,f,d))){if(this.fsw.closed){u=void 0;return}(d===r||!r&&!c.has(d))&&(this.fsw._incrReadyCount(),f=i.join(a,i.relative(a,f)),this._addToNodeFs(f,t,n,o+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,i)=>{if(!u)return i();u.once(C,()=>{if(this.fsw.closed){u=void 0;return}let i=s?s.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),u=void 0,i&&this._handleRead(e,!1,n,r,a,o,s)})})}async _handleDir(e,t,n,r,a,o,s){let c=this.fsw._getWatchedDir(i.dirname(e)),l=c.has(i.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!a&&!l&&this.fsw._emit(O.ADD_DIR,e,t),c.add(i.basename(e)),this.fsw._getWatchedDir(e);let u,d,f=this.fsw.options.depth;if((f==null||r<=f)&&!this.fsw._symlinkPaths.has(s)){if(!a&&(await this._handleRead(e,n,o,a,e,r,u),this.fsw.closed))return;d=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,o,a,e,r,u)})}return d}async _addToNodeFs(e,t,n,r,a){let o=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return o(),!1;let s=this.fsw._getWatchHelpers(e);n&&(s.filterPath=e=>n.filterPath(e),s.filterDir=e=>n.filterDir(e));try{let n=await ve[s.statMethod](s.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(s.watchPath,n))return o(),!1;let l=this.fsw.options.followSymlinks,u;if(n.isDirectory()){let o=i.resolve(e),d=l?await c(e):e;if(this.fsw.closed||(u=await this._handleDir(s.watchPath,n,t,r,a,s,d),this.fsw.closed))return;o!==d&&d!==void 0&&this.fsw._symlinkPaths.set(o,d)}else if(n.isSymbolicLink()){let a=l?await c(e):e;if(this.fsw.closed)return;let o=i.dirname(s.watchPath);if(this.fsw._getWatchedDir(o).add(s.watchPath),this.fsw._emit(O.ADD,s.watchPath,n),u=await this._handleDir(o,n,t,r,e,s,a),this.fsw.closed)return;a!==void 0&&this.fsw._symlinkPaths.set(i.resolve(e),a)}else u=this._handleFile(s.watchPath,n,t);return o(),u&&this.fsw._addPathCloser(e,u),!1}catch(t){if(this.fsw._handleError(t))return o(),e}}};const U=`/`,Ce=`//`,W=`.`,we=`..`,Te=`string`,Ee=/\\/g,G=/\/\//,De=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,Oe=/^\.[/\\]/;function K(e){return Array.isArray(e)?e:[e]}const q=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function ke(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=i.relative(e.path,t);return n?!n.startsWith(`..`)&&!i.isAbsolute(n):!1}return!1}:()=>!1}function Ae(e){if(typeof e!=`string`)throw Error(`string expected`);e=i.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let n=/\/\//;for(;e.match(n);)e=e.replace(n,`/`);return t&&(e=`/`+e),e}function J(e,t,n){let r=Ae(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function je(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=K(e),r=n.map(e=>ke(e));return t==null?(e,t)=>J(r,e,t):J(r,t)}const Y=e=>{let t=K(e).flat();if(!t.every(e=>typeof e===Te))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Z)},X=e=>{let t=e.replace(Ee,U),n=!1;for(t.startsWith(Ce)&&(n=!0);t.match(G);)t=t.replace(G,U);return n&&(t=U+t),t},Z=e=>X(i.normalize(X(e))),Q=(e=``)=>t=>typeof t==`string`?Z(i.isAbsolute(t)?t:i.join(e,t)):t,Me=(e,t)=>i.isAbsolute(e)?e:i.join(t,e),Ne=Object.freeze(new Set);var $=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==W&&e!==we&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await s(n)}catch{this._removeWatcher&&this._removeWatcher(i.dirname(n),i.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=w,this.items=Ne,Object.freeze(this)}};const Pe=`stat`,Fe=`lstat`;var Ie=class{constructor(e,t,n){this.fsw=n;let r=e;this.path=e=e.replace(Oe,``),this.watchPath=r,this.fullWatchPath=i.resolve(r),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Pe:Fe}entryPath(e){return i.join(this.watchPath,i.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Le=class extends u{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?K(e.ignored):K([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};ge&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=w,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new Se(this),Object.freeze(r)}_addIgnoredPath(e){if(q(e)){for(let t of this._ignoredPaths)if(q(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)q(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:r}=this.options;this.closed=!1,this._closePromise=void 0;let a=Y(e);return r&&(a=a.map(e=>{let t=Me(e,r);return t})),a.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=a.length,Promise.all(a.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(i.dirname(e),i.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Y(e),{cwd:n}=this.options;return t.forEach(e=>{!i.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=i.join(n,e)),e=i.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let r=this.options.cwd?i.relative(this.options.cwd,n):n,a=r||W;e[a]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let r=this.options;E&&(t=i.normalize(t)),r.cwd&&(t=i.relative(r.cwd,t));let a=[t];n!=null&&a.push(n);let o=r.awaitWriteFinish,s;if(o&&(s=this._pendingWrites.get(t)))return s.lastChange=new Date,this;if(r.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof r.atomic==`number`?r.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(o&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,a[0]=t,this.emitWithAll(e,a)):n&&(a.length>1?a[1]=n:a.push(n),this.emitWithAll(e,a))};return this._awaitWriteFinish(t,o.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(r.alwaysStat&&n===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=r.cwd?i.join(r.cwd,t):t,n;try{n=await l(e)}catch{}if(!n||this.closed)return;a.push(n)}return this.emitWithAll(e,a),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,n,r,a){let o=this.options.awaitWriteFinish;if(typeof o!=`object`)return;let s=o.pollInterval,c,l=t;this.options.cwd&&!i.isAbsolute(t)&&(l=i.join(this.options.cwd,t));let u=new Date,d=this._pendingWrites;function f(r){e(l,(e,i)=>{if(e||!d.has(t)){e&&e.code!==`ENOENT`&&a(e);return}let o=Number(new Date);r&&i.size!==r.size&&(d.get(t).lastChange=o);let l=d.get(t),u=o-l.lastChange;u>=n?(d.delete(t),a(void 0,i)):c=setTimeout(f,s,i)})}d.has(t)||(d.set(t,{lastChange:u,cancelWait:()=>(d.delete(t),clearTimeout(c),r)}),c=setTimeout(f,s))}_isIgnored(e,t){if(this.options.atomic&&De.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map(Q(e)),r=[...this._ignoredPaths],i=[...r.map(Q(e)),...n];this._userIgnored=je(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new Ie(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=i.resolve(e);return this._watched.has(t)||this._watched.set(t,new $(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let r=i.join(e,t),a=i.resolve(r);if(n??=this._watched.has(r)||this._watched.has(a),!this._throttle(`remove`,r,100))return;!n&&this._watched.size===1&&this.add(e,t,!0);let o=this._getWatchedDir(r),s=o.getChildren();s.forEach(e=>this._remove(r,e));let c=this._getWatchedDir(e),l=c.has(t);c.remove(t),this._symlinkPaths.has(a)&&this._symlinkPaths.delete(a);let u=r;if(this.options.cwd&&(u=i.relative(this.options.cwd,r)),this.options.awaitWriteFinish&&this._pendingWrites.has(u)){let e=this._pendingWrites.get(u).cancelWait();if(e===D.ADD)return}this._watched.delete(r),this._watched.delete(a);let d=n?D.UNLINK_DIR:D.UNLINK;l&&!this._isIgnored(r)&&this._emit(d,r),this._closePath(r)}_closePath(e){this._closeFile(e);let t=i.dirname(e);this._getWatchedDir(t).remove(i.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=ue(e,n);return this._streams.add(r),r.once(fe,()=>{r=void 0}),r.once(C,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Re(e,t={}){let n=new Le(t);return n.add(e),n}export{Re as watch};
|
|
1
|
+
import{stat as e,unwatchFile as t,watch as n,watchFile as r}from"fs";import{type as i}from"os";import*as a from"path";import{lstat as o,open as s,readdir as c,realpath as l,stat as u}from"fs/promises";import{EventEmitter as d}from"events";import{lstat as f,readdir as p,realpath as ee,stat as te}from"node:fs/promises";import{Readable as ne}from"node:stream";import{join as re,relative as ie,resolve as m,sep as ae}from"node:path";const h={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},g={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:h.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(g);const _=`READDIRP_RECURSIVE_ERROR`,v=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,_]),y=[h.DIR_TYPE,h.EVERYTHING_TYPE,h.FILE_DIR_TYPE,h.FILE_TYPE],oe=new Set([h.DIR_TYPE,h.EVERYTHING_TYPE,h.FILE_DIR_TYPE]),se=new Set([h.EVERYTHING_TYPE,h.FILE_DIR_TYPE,h.FILE_TYPE]),ce=e=>v.has(e.code),b=process.platform===`win32`,x=e=>!0,S=e=>{if(e===void 0)return x;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return x};var le=class extends ne{constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...g,...e},{root:n,type:r}=t;this._fileFilter=S(t.fileFilter),this._directoryFilter=S(t.directoryFilter);let i=t.lstat?f:te;b?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth??g.depth,this._wantsDir=r?oe.has(r):!1,this._wantsFile=r?se.has(r):!1,this._wantsEverything=r===h.EVERYTHING_TYPE,this._root=m(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await p(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=m(re(t,r));n={path:ie(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){ce(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await ee(t),n=await f(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===ae){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=_,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function ue(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=h.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!y.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${y.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new le(t)}const de=`data`,C=`end`,fe=`close`,w=()=>{},T=process.platform,E=T===`win32`,pe=T===`darwin`,me=T===`linux`,he=T===`freebsd`,ge=i()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,_e=`watch`,ve={lstat:o,stat:u},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,M=[k,A,j],N=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),P=e=>N.has(a.extname(e).slice(1).toLowerCase()),F=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},I=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ye=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},L=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},R=e=>e instanceof Set?e.size===0:!e,z=new Map;function B(e,t,r,i,o){let s=(t,n)=>{r(e),o(t,n,{watchedPath:e}),n&&e!==n&&V(a.resolve(e,n),k,a.join(e,n))};try{return n(e,{persistent:t.persistent},s)}catch(e){i(e);return}}const V=(e,t,n,r,i)=>{let a=z.get(e);a&&F(a[t],e=>{e(n,r,i)})},be=(e,t,n,r)=>{let{listener:i,errHandler:a,rawEmitter:o}=r,c=z.get(t),l;if(!n.persistent)return l=B(e,n,i,a,o),l?l.close.bind(l):void 0;if(c)I(c,k,i),I(c,A,a),I(c,j,o);else{if(l=B(e,n,V.bind(null,t,k),a,V.bind(null,t,j)),!l)return;l.on(O.ERROR,async n=>{let r=V.bind(null,t,A);if(c&&(c.watcherUnusable=!0),E&&n.code===`EPERM`)try{let t=await s(e,`r`);await t.close(),r(n)}catch{}else r(n)}),c={listeners:i,errHandlers:a,rawEmitters:o,watcher:l},z.set(t,c)}return()=>{L(c,k,i),L(c,A,a),L(c,j,o),R(c.listeners)&&(c.watcher.close(),z.delete(t),M.forEach(ye(c)),c.watcher=void 0,Object.freeze(c))}},H=new Map,xe=(e,n,i,a)=>{let{listener:o,rawEmitter:s}=a,c=H.get(n),l=c&&c.options;return l&&(l.persistent<i.persistent||l.interval>i.interval)&&(t(n),c=void 0),c?(I(c,k,o),I(c,j,s)):(c={listeners:o,rawEmitters:s,options:i,watcher:r(n,i,(t,r)=>{F(c.rawEmitters,e=>{e(O.CHANGE,n,{curr:t,prev:r})});let i=t.mtimeMs;(t.size!==r.size||i>r.mtimeMs||i===0)&&F(c.listeners,n=>n(e,t))})},H.set(n,c)),()=>{L(c,k,o),L(c,j,s),R(c.listeners)&&(H.delete(n),t(n),c.options=c.watcher=void 0,Object.freeze(c))}};var Se=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,r=a.dirname(e),i=a.basename(e),o=this.fsw._getWatchedDir(r);o.add(i);let s=a.resolve(e),c={persistent:n.persistent};t||=w;let l;if(n.usePolling){let r=n.interval!==n.binaryInterval;c.interval=r&&P(i)?n.binaryInterval:n.interval,l=xe(e,s,c,{listener:t,rawEmitter:this.fsw._emitRaw})}else l=be(e,s,c,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(e,t,n){if(this.fsw.closed)return;let r=a.dirname(e),i=a.basename(e),o=this.fsw._getWatchedDir(r),s=t;if(o.has(i))return;let c=async(t,n)=>{if(this.fsw._throttle(_e,e,5)){if(!n||n.mtimeMs===0)try{let n=await u(e);if(this.fsw.closed)return;let r=n.atimeMs,i=n.mtimeMs;if((!r||r<=i||i!==s.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(pe||me||he)&&s.ino!==n.ino){this.fsw._closeFile(t),s=n;let r=this._watchWithNodeFs(e,c);r&&this.fsw._addPathCloser(t,r)}else s=n}catch{this.fsw._remove(r,i)}else if(o.has(i)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==s.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),s=n}}},l=this._watchWithNodeFs(e,c);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return l}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let i=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await l(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(a.has(r)?this.fsw._symlinkPaths.get(i)!==t&&(this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.CHANGE,n,e.stats)):(a.add(r),this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(i))return!0;this.fsw._symlinkPaths.set(i,!0)}_handleRead(e,t,n,r,i,o,s){if(e=a.join(e,``),s=this.fsw._throttle(`readdir`,e,1e3),!s)return;let c=this.fsw._getWatchedDir(n.path),l=new Set,u=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(u)return u.on(de,async s=>{if(this.fsw.closed){u=void 0;return}let d=s.path,f=a.join(e,d);if(l.add(d),!(s.stats.isSymbolicLink()&&await this._handleSymlink(s,e,f,d))){if(this.fsw.closed){u=void 0;return}(d===r||!r&&!c.has(d))&&(this.fsw._incrReadyCount(),f=a.join(i,a.relative(i,f)),this._addToNodeFs(f,t,n,o+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,a)=>{if(!u)return a();u.once(C,()=>{if(this.fsw.closed){u=void 0;return}let a=s?s.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),u=void 0,a&&this._handleRead(e,!1,n,r,i,o,s)})})}async _handleDir(e,t,n,r,i,o,s){let c=this.fsw._getWatchedDir(a.dirname(e)),l=c.has(a.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!i&&!l&&this.fsw._emit(O.ADD_DIR,e,t),c.add(a.basename(e)),this.fsw._getWatchedDir(e);let u,d,f=this.fsw.options.depth;if((f==null||r<=f)&&!this.fsw._symlinkPaths.has(s)){if(!i&&(await this._handleRead(e,n,o,i,e,r,u),this.fsw.closed))return;d=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,o,i,e,r,u)})}return d}async _addToNodeFs(e,t,n,r,i){let o=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return o(),!1;let s=this.fsw._getWatchHelpers(e);n&&(s.filterPath=e=>n.filterPath(e),s.filterDir=e=>n.filterDir(e));try{let n=await ve[s.statMethod](s.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(s.watchPath,n))return o(),!1;let c=this.fsw.options.followSymlinks,u;if(n.isDirectory()){let o=a.resolve(e),d=c?await l(e):e;if(this.fsw.closed||(u=await this._handleDir(s.watchPath,n,t,r,i,s,d),this.fsw.closed))return;o!==d&&d!==void 0&&this.fsw._symlinkPaths.set(o,d)}else if(n.isSymbolicLink()){let i=c?await l(e):e;if(this.fsw.closed)return;let o=a.dirname(s.watchPath);if(this.fsw._getWatchedDir(o).add(s.watchPath),this.fsw._emit(O.ADD,s.watchPath,n),u=await this._handleDir(o,n,t,r,e,s,i),this.fsw.closed)return;i!==void 0&&this.fsw._symlinkPaths.set(a.resolve(e),i)}else u=this._handleFile(s.watchPath,n,t);return o(),u&&this.fsw._addPathCloser(e,u),!1}catch(t){if(this.fsw._handleError(t))return o(),e}}};const U=`/`,Ce=`//`,W=`.`,we=`..`,Te=`string`,Ee=/\\/g,G=/\/\//,De=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,Oe=/^\.[/\\]/;function K(e){return Array.isArray(e)?e:[e]}const q=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function ke(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=a.relative(e.path,t);return n?!n.startsWith(`..`)&&!a.isAbsolute(n):!1}return!1}:()=>!1}function Ae(e){if(typeof e!=`string`)throw Error(`string expected`);e=a.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let n=/\/\//;for(;e.match(n);)e=e.replace(n,`/`);return t&&(e=`/`+e),e}function J(e,t,n){let r=Ae(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function je(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=K(e),r=n.map(e=>ke(e));return t==null?(e,t)=>J(r,e,t):J(r,t)}const Y=e=>{let t=K(e).flat();if(!t.every(e=>typeof e===Te))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Z)},X=e=>{let t=e.replace(Ee,U),n=!1;for(t.startsWith(Ce)&&(n=!0);t.match(G);)t=t.replace(G,U);return n&&(t=U+t),t},Z=e=>X(a.normalize(X(e))),Q=(e=``)=>t=>typeof t==`string`?Z(a.isAbsolute(t)?t:a.join(e,t)):t,Me=(e,t)=>a.isAbsolute(e)?e:a.join(t,e),Ne=Object.freeze(new Set);var $=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==W&&e!==we&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await c(n)}catch{this._removeWatcher&&this._removeWatcher(a.dirname(n),a.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=w,this.items=Ne,Object.freeze(this)}};const Pe=`stat`,Fe=`lstat`;var Ie=class{constructor(e,t,n){this.fsw=n;let r=e;this.path=e=e.replace(Oe,``),this.watchPath=r,this.fullWatchPath=a.resolve(r),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Pe:Fe}entryPath(e){return a.join(this.watchPath,a.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Le=class extends d{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?K(e.ignored):K([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};ge&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=w,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new Se(this),Object.freeze(r)}_addIgnoredPath(e){if(q(e)){for(let t of this._ignoredPaths)if(q(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)q(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:r}=this.options;this.closed=!1,this._closePromise=void 0;let i=Y(e);return r&&(i=i.map(e=>{let t=Me(e,r);return t})),i.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=i.length,Promise.all(i.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(a.dirname(e),a.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Y(e),{cwd:n}=this.options;return t.forEach(e=>{!a.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=a.join(n,e)),e=a.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let r=this.options.cwd?a.relative(this.options.cwd,n):n,i=r||W;e[i]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let r=this.options;E&&(t=a.normalize(t)),r.cwd&&(t=a.relative(r.cwd,t));let i=[t];n!=null&&i.push(n);let o=r.awaitWriteFinish,s;if(o&&(s=this._pendingWrites.get(t)))return s.lastChange=new Date,this;if(r.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...i]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof r.atomic==`number`?r.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(o&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,i[0]=t,this.emitWithAll(e,i)):n&&(i.length>1?i[1]=n:i.push(n),this.emitWithAll(e,i))};return this._awaitWriteFinish(t,o.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(r.alwaysStat&&n===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=r.cwd?a.join(r.cwd,t):t,n;try{n=await u(e)}catch{}if(!n||this.closed)return;i.push(n)}return this.emitWithAll(e,i),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,n,r,i){let o=this.options.awaitWriteFinish;if(typeof o!=`object`)return;let s=o.pollInterval,c,l=t;this.options.cwd&&!a.isAbsolute(t)&&(l=a.join(this.options.cwd,t));let u=new Date,d=this._pendingWrites;function f(r){e(l,(e,a)=>{if(e||!d.has(t)){e&&e.code!==`ENOENT`&&i(e);return}let o=Number(new Date);r&&a.size!==r.size&&(d.get(t).lastChange=o);let l=d.get(t),u=o-l.lastChange;u>=n?(d.delete(t),i(void 0,a)):c=setTimeout(f,s,a)})}d.has(t)||(d.set(t,{lastChange:u,cancelWait:()=>(d.delete(t),clearTimeout(c),r)}),c=setTimeout(f,s))}_isIgnored(e,t){if(this.options.atomic&&De.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map(Q(e)),r=[...this._ignoredPaths],i=[...r.map(Q(e)),...n];this._userIgnored=je(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new Ie(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=a.resolve(e);return this._watched.has(t)||this._watched.set(t,new $(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let r=a.join(e,t),i=a.resolve(r);if(n??=this._watched.has(r)||this._watched.has(i),!this._throttle(`remove`,r,100))return;!n&&this._watched.size===1&&this.add(e,t,!0);let o=this._getWatchedDir(r),s=o.getChildren();s.forEach(e=>this._remove(r,e));let c=this._getWatchedDir(e),l=c.has(t);c.remove(t),this._symlinkPaths.has(i)&&this._symlinkPaths.delete(i);let u=r;if(this.options.cwd&&(u=a.relative(this.options.cwd,r)),this.options.awaitWriteFinish&&this._pendingWrites.has(u)){let e=this._pendingWrites.get(u).cancelWait();if(e===D.ADD)return}this._watched.delete(r),this._watched.delete(i);let d=n?D.UNLINK_DIR:D.UNLINK;l&&!this._isIgnored(r)&&this._emit(d,r),this._closePath(r)}_closePath(e){this._closeFile(e);let t=a.dirname(e);this._getWatchedDir(t).remove(a.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=ue(e,n);return this._streams.add(r),r.once(fe,()=>{r=void 0}),r.once(C,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Re(e,t={}){let n=new Le(t);return n.add(e),n}export{Re as watch};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cliCore-
|
|
1
|
+
const e=require(`./cliCore-BOwdDcP4.cjs`);exports.CLI=e.CLI;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CLI as e}from"./cliCore-
|
|
1
|
+
import{CLI as e}from"./cliCore-CYhcPSJT.js";export{e as CLI};
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`chalk`)),n=e.__toESM(require(`commander`)),r=e.__toESM(require(`@stackone/connect-sdk`)),i=e.__toESM(require(`fs`)),a=e.__toESM(require(`ora`)),o=e.__toESM(require(`path`)),s=e.__toESM(require(`url`));var c=class{static info(e){console.info(t.default.blue(`ℹ`),e)}static warn(e){console.info(t.default.yellow(`⚠`),e)}static error(e){console.info(t.default.red(`✗`),e)}static success(e){console.info(t.default.green(`✓`),e)}},l=class{async execute(e){let{watchMode:n,fileOrDir:r}=e,o=(0,a.default)(`Watching for changes...`),s=()=>{console.clear(),console.info(t.default.yellow(`Watch mode enabled. Press "q" to quit.
|
|
2
|
-
`))};if(r){try{(0,i.statSync)(r)}catch{c.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:e}=await Promise.resolve().then(()=>require(`./esm-Chmlhd00.cjs`)),n=await import(`readline`),i=n.createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let a=()=>{console.info(t.default.grey(`
|
|
3
|
-
|
|
4
|
-
Exiting watch mode...`)),c.close(),o.stop(),i.close(),process.exit(0)};s(),console.info(t.default.blue(`Running connector(s) validations...`)),await u(r),o.start();let c=e(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});c.on(`change`,async e=>{s(),o.stop(),console.info(t.default.blue(`File change detected. Running connector(s) validations...`)),await u(r),o.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&a()}),process.on(`SIGINT`,()=>{a()})}else await u(r),process.exit(0)}}};const u=async e=>{let t=(0,i.statSync)(e);if(t.isDirectory()){let t=(0,i.readdirSync)(e),n=t.filter(e=>e.endsWith(`.s1.yaml`));if(n.length===0){c.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let r=0,a=0;for(let t of n){let n=`${e}/${t}`,o=(0,i.statSync)(n);if(o.isFile()){let e=await d(n);e?r++:a++}}c.info(`Validation completed: ${r} valid, ${a} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await d(e):c.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},d=async e=>{let n=(0,r.loadConnector)(e),i=(0,r.validateYamlConnector)(n),a=i?.errors??[];if(i.success){let t=e.split(`/`).pop()||e;return c.success(`Connector ${t} is valid!\n`),!0}else if(a.length>0)return c.error(`Connector ${e} is not valid. Please fix the following errors:\n`),a.forEach(e=>{console.info(t.default.red(`- L${e.line}: ${e.message}`))}),console.info(`
|
|
5
|
-
`),!1;else return c.error(`Connector ${e} is not valid. Please check the file for errors.`),!1},f=()=>{try{let e=(0,s.fileURLToPath)(require(`url`).pathToFileURL(__filename).href),t=(0,o.dirname)(e),n=(0,o.join)(t,`..`,`package.json`),r=JSON.parse((0,i.readFileSync)(n,`utf8`));return r.version}catch{return`unknown`}};var p=class{constructor(e=new n.Command,t=f()){this.program=e,this.version=t,this.setupProgram(),this.registerCommands()}setupProgram(){this.program.name(`stackone`).description(`StackOne CLI`).version(this.version)}registerCommands(){let e=new l;this.program.configureOutput({writeOut:e=>process.stdout.write(e),writeErr:e=>process.stderr.write(e),outputError:(e,n)=>{n(t.default.red(e))}}),this.program.command(`validate`).option(`-w, --watch`,`Run in watch mode`).addArgument(new n.Argument(`<path>`,`Connector file or directory with connectors to validate`)).description(`Validate a StackOne connector`).action((t,n)=>{e.execute({watchMode:n.watch,fileOrDir:t})}),this.program.command(`version`).description(`Show version information`).action(()=>{console.info(`${t.default.greenBright(`StackOne`)} ${t.default.grey(`CLI`)} ${t.default.whiteBright(this.version)}`),process.exit(0)})}run(){this.program.parse(process.argv)}};Object.defineProperty(exports,`CLI`,{enumerable:!0,get:function(){return p}});
|
package/dist/cliCore-eRQ8Iw8F.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import e from"chalk";import{Argument as t,Command as n}from"commander";import{loadConnector as r,validateYamlConnector as i}from"@stackone/connect-sdk";import{readFileSync as a,readdirSync as o,statSync as s}from"fs";import c from"ora";import{dirname as l,join as u}from"path";import{fileURLToPath as d}from"url";var f=class{static info(t){console.info(e.blue(`ℹ`),t)}static warn(t){console.info(e.yellow(`⚠`),t)}static error(t){console.info(e.red(`✗`),t)}static success(t){console.info(e.green(`✓`),t)}},p=class{async execute(t){let{watchMode:n,fileOrDir:r}=t,i=c(`Watching for changes...`),a=()=>{console.clear(),console.info(e.yellow(`Watch mode enabled. Press "q" to quit.
|
|
2
|
-
`))};if(r){try{s(r)}catch{f.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:t}=await import(`./esm-BenXeAeS.js`),n=await import(`readline`),o=n.createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let s=()=>{console.info(e.grey(`
|
|
3
|
-
|
|
4
|
-
Exiting watch mode...`)),c.close(),i.stop(),o.close(),process.exit(0)};a(),console.info(e.blue(`Running connector(s) validations...`)),await m(r),i.start();let c=t(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});c.on(`change`,async t=>{a(),i.stop(),console.info(e.blue(`File change detected. Running connector(s) validations...`)),await m(r),i.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&s()}),process.on(`SIGINT`,()=>{s()})}else await m(r),process.exit(0)}}};const m=async e=>{let t=s(e);if(t.isDirectory()){let t=o(e),n=t.filter(e=>e.endsWith(`.s1.yaml`));if(n.length===0){f.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let r=0,i=0;for(let t of n){let n=`${e}/${t}`,a=s(n);if(a.isFile()){let e=await h(n);e?r++:i++}}f.info(`Validation completed: ${r} valid, ${i} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await h(e):f.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},h=async t=>{let n=r(t),a=i(n),o=a?.errors??[];if(a.success){let e=t.split(`/`).pop()||t;return f.success(`Connector ${e} is valid!\n`),!0}else if(o.length>0)return f.error(`Connector ${t} is not valid. Please fix the following errors:\n`),o.forEach(t=>{console.info(e.red(`- L${t.line}: ${t.message}`))}),console.info(`
|
|
5
|
-
`),!1;else return f.error(`Connector ${t} is not valid. Please check the file for errors.`),!1},g=()=>{try{let e=d(import.meta.url),t=l(e),n=u(t,`..`,`package.json`),r=JSON.parse(a(n,`utf8`));return r.version}catch{return`unknown`}};var _=class{constructor(e=new n,t=g()){this.program=e,this.version=t,this.setupProgram(),this.registerCommands()}setupProgram(){this.program.name(`stackone`).description(`StackOne CLI`).version(this.version)}registerCommands(){let n=new p;this.program.configureOutput({writeOut:e=>process.stdout.write(e),writeErr:e=>process.stderr.write(e),outputError:(t,n)=>{n(e.red(t))}}),this.program.command(`validate`).option(`-w, --watch`,`Run in watch mode`).addArgument(new t(`<path>`,`Connector file or directory with connectors to validate`)).description(`Validate a StackOne connector`).action((e,t)=>{n.execute({watchMode:t.watch,fileOrDir:e})}),this.program.command(`version`).description(`Show version information`).action(()=>{console.info(`${e.greenBright(`StackOne`)} ${e.grey(`CLI`)} ${e.whiteBright(this.version)}`),process.exit(0)})}run(){this.program.parse(process.argv)}};export{_ as CLI};
|