@openvcs/sdk 0.2.0 → 0.2.1

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 CHANGED
@@ -7,7 +7,7 @@
7
7
  OpenVCS SDK for npm-based plugin development.
8
8
 
9
9
  Install this package in plugin projects, scaffold a starter plugin, and package
10
- plugins into `.ovcsp` bundles with `npm run build`.
10
+ plugins into `.ovcsp` bundles.
11
11
 
12
12
  ## Install
13
13
 
@@ -15,18 +15,53 @@ plugins into `.ovcsp` bundles with `npm run build`.
15
15
  npm install --save-dev @openvcs/sdk
16
16
  ```
17
17
 
18
+ This package installs a local CLI command named `openvcs`.
19
+
20
+ One-off usage without adding to a project:
21
+
22
+ ```bash
23
+ npx --package @openvcs/sdk openvcs --help
24
+ ```
25
+
26
+ ## SDK development
27
+
28
+ This repository is authored in TypeScript under `src/` and compiles runtime files
29
+ to `bin/` and `lib/`.
30
+
31
+ Build the SDK:
32
+
33
+ ```bash
34
+ npm run build
35
+ ```
36
+
37
+ Run tests (builds first):
38
+
39
+ ```bash
40
+ npm test
41
+ ```
42
+
43
+ Run the local CLI through npm scripts:
44
+
45
+ ```bash
46
+ npm run openvcs -- --help
47
+ npm run openvcs -- init --help
48
+ npm run openvcs -- dist --help
49
+ ```
50
+
18
51
  ## Scaffold a plugin
19
52
 
20
53
  Interactive module plugin scaffold:
21
54
 
22
55
  ```bash
23
- npx @openvcs/sdk init my-plugin
56
+ openvcs init my-plugin
24
57
  ```
25
58
 
59
+ The generated module template includes TypeScript and Node typings (`@types/node`).
60
+
26
61
  Interactive theme plugin scaffold:
27
62
 
28
63
  ```bash
29
- npx @openvcs/sdk init --theme my-theme
64
+ openvcs init --theme my-theme
30
65
  ```
31
66
 
32
67
  ## Build a `.ovcsp` bundle
@@ -39,6 +74,9 @@ npm run build
39
74
 
40
75
  This produces `dist/<plugin-id>.ovcsp`.
41
76
 
77
+ `.ovcsp` is a gzip-compressed tar archive (`tar.gz`) that contains a top-level
78
+ `<plugin-id>/` directory with `openvcs.plugin.json` and plugin runtime assets.
79
+
42
80
  Dependency behavior while packaging:
43
81
 
44
82
  - npm dependency bundling is enabled by default when `package.json` exists.
@@ -48,11 +86,28 @@ Dependency behavior while packaging:
48
86
  - Disable npm dependency processing with `--no-npm-deps`.
49
87
  - Native Node addons (`*.node`) are rejected for portable bundles.
50
88
 
51
- ## Native implementation
89
+ ## CLI usage
90
+
91
+ Package a plugin manually:
92
+
93
+ ```bash
94
+ openvcs dist --plugin-dir /path/to/plugin --out /path/to/dist
95
+ ```
96
+
97
+ Show command help:
98
+
99
+ ```bash
100
+ openvcs --help
101
+ openvcs dist --help
102
+ openvcs init --help
103
+ ```
104
+
105
+ ## Releases
52
106
 
53
- The native implementation (Rust crate and binaries) lives in `native/`.
107
+ Stable releases are published from `.github/workflows/release.yml`.
54
108
 
55
- See `native/README.md` for Rust-focused development and crates.io publishing.
109
+ - npm publishes use npm Trusted Publishing (OIDC), so no `NPM_TOKEN` is required.
110
+ - `npm prepack` compiles TypeScript so published packages include `bin/` and `lib/` JS outputs.
56
111
 
57
112
  ## License
58
113
 
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/openvcs.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cli_1 = require("../lib/cli");
5
+ (0, cli_1.runCli)(process.argv.slice(2)).catch((error) => {
6
+ const detail = error instanceof Error ? error.message : String(error);
7
+ process.stderr.write(`${detail}\n`);
8
+ process.exit(1);
9
+ });
package/lib/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function runCli(args: string[]): Promise<void>;
package/lib/cli.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCli = runCli;
4
+ const dist_1 = require("./dist");
5
+ const init_1 = require("./init");
6
+ const packageJson = require("../package.json");
7
+ function hasCode(error, code) {
8
+ return (typeof error === "object" &&
9
+ error !== null &&
10
+ "code" in error &&
11
+ error.code === code);
12
+ }
13
+ function usage() {
14
+ return "Usage: openvcs <command> [options]\n\nCommands:\n dist [args] Package plugin into .ovcsp\n init [--theme] [dir] Interactively scaffold a plugin project\n -v, --version Show version information\n\nDist args:\n --plugin-dir <path> Plugin root containing openvcs.plugin.json\n --out <path> Output directory (default: ./dist)\n --no-npm-deps Skip npm dependency bundling\n -V, --verbose Verbose output\n";
15
+ }
16
+ async function runCli(args) {
17
+ if (args.length === 0) {
18
+ process.stderr.write(usage());
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ if (args.includes("-v") || args.includes("--version")) {
23
+ process.stdout.write(`openvcs ${packageJson.version}\n`);
24
+ return;
25
+ }
26
+ const [command, ...rest] = args;
27
+ if (command === "help" || command === "--help" || command === "-h") {
28
+ process.stdout.write(usage());
29
+ return;
30
+ }
31
+ if (command === "dist") {
32
+ if (rest.includes("--help")) {
33
+ process.stdout.write((0, dist_1.distUsage)());
34
+ return;
35
+ }
36
+ try {
37
+ const parsed = (0, dist_1.parseDistArgs)(rest);
38
+ const outPath = await (0, dist_1.bundlePlugin)(parsed);
39
+ process.stdout.write(`${outPath}\n`);
40
+ return;
41
+ }
42
+ catch (error) {
43
+ if (hasCode(error, "USAGE")) {
44
+ throw new Error((0, dist_1.distUsage)());
45
+ }
46
+ throw error;
47
+ }
48
+ }
49
+ if (command === "init") {
50
+ if (rest.includes("--help")) {
51
+ process.stdout.write((0, init_1.initUsage)());
52
+ return;
53
+ }
54
+ try {
55
+ const targetDir = await (0, init_1.runInitCommand)(rest);
56
+ process.stdout.write(`Initialized plugin at ${targetDir}\n`);
57
+ return;
58
+ }
59
+ catch (error) {
60
+ if (hasCode(error, "USAGE")) {
61
+ throw new Error((0, init_1.initUsage)());
62
+ }
63
+ throw error;
64
+ }
65
+ }
66
+ throw new Error(`unknown command: ${command}`);
67
+ }
package/lib/dist.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ interface DistArgs {
2
+ pluginDir: string;
3
+ outDir: string;
4
+ verbose: boolean;
5
+ noNpmDeps: boolean;
6
+ }
7
+ interface ManifestInfo {
8
+ pluginId: string;
9
+ moduleExec: string | undefined;
10
+ manifestPath: string;
11
+ }
12
+ export declare function distUsage(commandName?: string): string;
13
+ export declare function parseDistArgs(args: string[]): DistArgs;
14
+ declare function readManifest(pluginDir: string): ManifestInfo;
15
+ declare function validateDeclaredModuleExec(pluginDir: string, moduleExec: string | undefined): void;
16
+ declare function rejectNativeAddonsRecursive(dirPath: string): void;
17
+ declare function copyIcon(pluginDir: string, bundleDir: string): void;
18
+ declare function uniqueStagingDir(outDir: string): string;
19
+ declare function writeTarGz(outPath: string, baseDir: string, folderName: string): Promise<void>;
20
+ export declare function bundlePlugin(parsedArgs: DistArgs): Promise<string>;
21
+ export declare const __private: {
22
+ ICON_EXTENSIONS: string[];
23
+ copyIcon: typeof copyIcon;
24
+ readManifest: typeof readManifest;
25
+ rejectNativeAddonsRecursive: typeof rejectNativeAddonsRecursive;
26
+ uniqueStagingDir: typeof uniqueStagingDir;
27
+ validateDeclaredModuleExec: typeof validateDeclaredModuleExec;
28
+ writeTarGz: typeof writeTarGz;
29
+ };
30
+ export {};
package/lib/dist.js ADDED
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__private = void 0;
4
+ exports.distUsage = distUsage;
5
+ exports.parseDistArgs = parseDistArgs;
6
+ exports.bundlePlugin = bundlePlugin;
7
+ const fs = require("node:fs");
8
+ const path = require("node:path");
9
+ const node_child_process_1 = require("node:child_process");
10
+ const tar = require("tar");
11
+ const fs_utils_1 = require("./fs-utils");
12
+ const ICON_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "avif", "svg"];
13
+ function npmExecutable() {
14
+ return process.platform === "win32" ? "npm.cmd" : "npm";
15
+ }
16
+ function distUsage(commandName = "openvcs") {
17
+ return `${commandName} dist [args]\n\n --plugin-dir <path> Plugin repository root (contains openvcs.plugin.json)\n --out <path> Output directory (default: ./dist)\n --no-npm-deps Disable npm dependency bundling (enabled by default)\n -V, --verbose Enable verbose output\n`;
18
+ }
19
+ function parseDistArgs(args) {
20
+ let pluginDir = process.cwd();
21
+ let outDir = "dist";
22
+ let verbose = false;
23
+ let noNpmDeps = false;
24
+ for (let index = 0; index < args.length; index += 1) {
25
+ const arg = args[index];
26
+ if (arg === "--plugin-dir") {
27
+ index += 1;
28
+ if (index >= args.length) {
29
+ throw new Error("missing value for --plugin-dir");
30
+ }
31
+ pluginDir = args[index];
32
+ continue;
33
+ }
34
+ if (arg === "--out") {
35
+ index += 1;
36
+ if (index >= args.length) {
37
+ throw new Error("missing value for --out");
38
+ }
39
+ outDir = args[index];
40
+ continue;
41
+ }
42
+ if (arg === "--no-npm-deps") {
43
+ noNpmDeps = true;
44
+ continue;
45
+ }
46
+ if (arg === "-V" || arg === "--verbose") {
47
+ verbose = true;
48
+ continue;
49
+ }
50
+ if (arg === "--help") {
51
+ const error = new Error(distUsage());
52
+ error.code = "USAGE";
53
+ throw error;
54
+ }
55
+ throw new Error(`unknown flag: ${arg}`);
56
+ }
57
+ return {
58
+ pluginDir: path.resolve(pluginDir),
59
+ outDir: path.resolve(outDir),
60
+ verbose,
61
+ noNpmDeps,
62
+ };
63
+ }
64
+ function readManifest(pluginDir) {
65
+ const manifestPath = path.join(pluginDir, "openvcs.plugin.json");
66
+ if (!fs.existsSync(manifestPath) || !fs.statSync(manifestPath).isFile()) {
67
+ throw new Error(`missing openvcs.plugin.json at ${manifestPath}`);
68
+ }
69
+ let manifest;
70
+ try {
71
+ manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
72
+ }
73
+ catch (error) {
74
+ const detail = error instanceof Error ? error.message : String(error);
75
+ throw new Error(`parse ${manifestPath}: ${detail}`);
76
+ }
77
+ const pluginId = typeof manifest.id === "string"
78
+ ? manifest.id.trim()
79
+ : "";
80
+ if (!pluginId) {
81
+ throw new Error(`manifest ${manifestPath} is missing a string 'id'`);
82
+ }
83
+ if (pluginId === "." || pluginId === ".." || pluginId.includes("/") || pluginId.includes("\\")) {
84
+ throw new Error(`manifest id must not contain path separators: ${pluginId}`);
85
+ }
86
+ const moduleValue = manifest.module;
87
+ const moduleExec = typeof moduleValue?.exec === "string" ? moduleValue.exec.trim() : undefined;
88
+ return {
89
+ pluginId,
90
+ moduleExec,
91
+ manifestPath,
92
+ };
93
+ }
94
+ function validateDeclaredModuleExec(pluginDir, moduleExec) {
95
+ if (!moduleExec) {
96
+ return;
97
+ }
98
+ const normalizedExec = moduleExec.trim();
99
+ const lowered = normalizedExec.toLowerCase();
100
+ if (!lowered.endsWith(".js") && !lowered.endsWith(".mjs") && !lowered.endsWith(".cjs")) {
101
+ throw new Error(`manifest exec must end with .js/.mjs/.cjs (Node runtime): ${moduleExec}`);
102
+ }
103
+ if (path.isAbsolute(normalizedExec)) {
104
+ throw new Error(`manifest module.exec must be a relative path under bin/: ${moduleExec}`);
105
+ }
106
+ const binDir = path.resolve(pluginDir, "bin");
107
+ const targetPath = path.resolve(binDir, normalizedExec);
108
+ if (!(0, fs_utils_1.isPathInside)(binDir, targetPath) || targetPath === binDir) {
109
+ throw new Error(`manifest module.exec must point to a file under bin/: ${moduleExec}`);
110
+ }
111
+ if (!fs.existsSync(targetPath) || !fs.lstatSync(targetPath).isFile()) {
112
+ throw new Error(`module entrypoint not found at ${targetPath}`);
113
+ }
114
+ }
115
+ function hasPackageJson(pluginDir) {
116
+ const packageJsonPath = path.join(pluginDir, "package.json");
117
+ return fs.existsSync(packageJsonPath) && fs.lstatSync(packageJsonPath).isFile();
118
+ }
119
+ function runCommand(program, args, cwd, verbose) {
120
+ if (verbose) {
121
+ process.stderr.write(`Running command in ${cwd}: ${program} ${args.join(" ")}\n`);
122
+ }
123
+ const result = (0, node_child_process_1.spawnSync)(program, args, {
124
+ cwd,
125
+ encoding: "utf8",
126
+ stdio: ["ignore", "pipe", "pipe"],
127
+ });
128
+ if (result.error) {
129
+ throw new Error(`failed to spawn '${program}' in ${cwd}: ${result.error.message}`);
130
+ }
131
+ if (result.status === 0) {
132
+ if (verbose) {
133
+ if (result.stdout?.trim()) {
134
+ process.stderr.write(`${result.stdout.trim()}\n`);
135
+ }
136
+ if (result.stderr?.trim()) {
137
+ process.stderr.write(`${result.stderr.trim()}\n`);
138
+ }
139
+ }
140
+ return;
141
+ }
142
+ throw new Error(`command failed (${program} ${args.join(" ")}), exit code ${result.status}, stdout='${(result.stdout || "").trim()}', stderr='${(result.stderr || "").trim()}'`);
143
+ }
144
+ function ensurePackageLock(pluginDir, verbose) {
145
+ if (!hasPackageJson(pluginDir)) {
146
+ return;
147
+ }
148
+ const lockPath = path.join(pluginDir, "package-lock.json");
149
+ if (fs.existsSync(lockPath) && fs.lstatSync(lockPath).isFile()) {
150
+ return;
151
+ }
152
+ if (verbose) {
153
+ process.stderr.write(`Generating package-lock.json in ${pluginDir}\n`);
154
+ }
155
+ runCommand(npmExecutable(), ["install", "--package-lock-only", "--ignore-scripts", "--no-audit", "--no-fund"], pluginDir, verbose);
156
+ }
157
+ function copyNpmFilesToStaging(pluginDir, bundleDir) {
158
+ const packageJsonPath = path.join(pluginDir, "package.json");
159
+ const lockPath = path.join(pluginDir, "package-lock.json");
160
+ if (!fs.existsSync(packageJsonPath) || !fs.lstatSync(packageJsonPath).isFile()) {
161
+ throw new Error(`missing package.json at ${packageJsonPath}`);
162
+ }
163
+ if (!fs.existsSync(lockPath) || !fs.lstatSync(lockPath).isFile()) {
164
+ throw new Error(`missing package-lock.json at ${lockPath}`);
165
+ }
166
+ (0, fs_utils_1.copyFileStrict)(packageJsonPath, path.join(bundleDir, "package.json"));
167
+ (0, fs_utils_1.copyFileStrict)(lockPath, path.join(bundleDir, "package-lock.json"));
168
+ }
169
+ function rejectNativeAddonsRecursive(dirPath) {
170
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
171
+ for (const entry of entries) {
172
+ const entryPath = path.join(dirPath, entry.name);
173
+ const stats = fs.lstatSync(entryPath);
174
+ if (stats.isSymbolicLink()) {
175
+ throw new Error(`plugin contains a symlink: ${entryPath}`);
176
+ }
177
+ if (stats.isDirectory()) {
178
+ rejectNativeAddonsRecursive(entryPath);
179
+ continue;
180
+ }
181
+ if (!stats.isFile()) {
182
+ continue;
183
+ }
184
+ if (entry.name.toLowerCase().endsWith(".node")) {
185
+ throw new Error(`native Node addon files are not supported in portable bundles: ${entryPath}`);
186
+ }
187
+ }
188
+ }
189
+ function installNpmDependencies(pluginDir, bundleDir, verbose) {
190
+ copyNpmFilesToStaging(pluginDir, bundleDir);
191
+ runCommand(npmExecutable(), ["ci", "--omit=dev", "--ignore-scripts", "--no-bin-links", "--no-audit", "--no-fund"], bundleDir, verbose);
192
+ const nodeModulesPath = path.join(bundleDir, "node_modules");
193
+ if (!fs.existsSync(nodeModulesPath)) {
194
+ return;
195
+ }
196
+ if (!fs.lstatSync(nodeModulesPath).isDirectory()) {
197
+ throw new Error(`npm install produced non-directory node_modules path: ${nodeModulesPath}`);
198
+ }
199
+ rejectNativeAddonsRecursive(nodeModulesPath);
200
+ }
201
+ function copyIcon(pluginDir, bundleDir) {
202
+ for (const extension of ICON_EXTENSIONS) {
203
+ const fileName = `icon.${extension}`;
204
+ const sourcePath = path.join(pluginDir, fileName);
205
+ if (!fs.existsSync(sourcePath)) {
206
+ continue;
207
+ }
208
+ (0, fs_utils_1.copyFileStrict)(sourcePath, path.join(bundleDir, fileName));
209
+ return;
210
+ }
211
+ }
212
+ function uniqueStagingDir(outDir) {
213
+ return path.join(outDir, `.openvcs-plugin-staging-${Date.now()}-${process.pid}`);
214
+ }
215
+ async function writeTarGz(outPath, baseDir, folderName) {
216
+ const folderPath = path.join(baseDir, folderName);
217
+ (0, fs_utils_1.rejectSymlinksRecursive)(folderPath);
218
+ await tar.create({
219
+ cwd: baseDir,
220
+ file: outPath,
221
+ gzip: true,
222
+ portable: true,
223
+ noMtime: true,
224
+ preservePaths: false,
225
+ strict: true,
226
+ }, [folderName]);
227
+ }
228
+ async function bundlePlugin(parsedArgs) {
229
+ const { pluginDir, outDir, verbose, noNpmDeps } = parsedArgs;
230
+ if (verbose) {
231
+ process.stderr.write(`Bundling plugin from: ${pluginDir}\n`);
232
+ }
233
+ const { pluginId, moduleExec, manifestPath } = readManifest(pluginDir);
234
+ const themesPath = path.join(pluginDir, "themes");
235
+ const hasThemes = fs.existsSync(themesPath) && fs.lstatSync(themesPath).isDirectory();
236
+ if (!moduleExec && !hasThemes) {
237
+ throw new Error("manifest has no module.exec or themes/");
238
+ }
239
+ validateDeclaredModuleExec(pluginDir, moduleExec);
240
+ (0, fs_utils_1.ensureDirectory)(outDir);
241
+ const stagingRoot = uniqueStagingDir(outDir);
242
+ const bundleDir = path.join(stagingRoot, pluginId);
243
+ (0, fs_utils_1.ensureDirectory)(bundleDir);
244
+ try {
245
+ (0, fs_utils_1.copyFileStrict)(manifestPath, path.join(bundleDir, "openvcs.plugin.json"));
246
+ copyIcon(pluginDir, bundleDir);
247
+ const sourceBinDir = path.join(pluginDir, "bin");
248
+ if (fs.existsSync(sourceBinDir) && fs.lstatSync(sourceBinDir).isDirectory()) {
249
+ (0, fs_utils_1.copyDirectoryRecursiveStrict)(sourceBinDir, path.join(bundleDir, "bin"));
250
+ }
251
+ if (hasThemes) {
252
+ (0, fs_utils_1.copyDirectoryRecursiveStrict)(themesPath, path.join(bundleDir, "themes"));
253
+ }
254
+ if (!noNpmDeps && hasPackageJson(pluginDir)) {
255
+ ensurePackageLock(pluginDir, verbose);
256
+ installNpmDependencies(pluginDir, bundleDir, verbose);
257
+ }
258
+ const outPath = path.join(outDir, `${pluginId}.ovcsp`);
259
+ if (fs.existsSync(outPath)) {
260
+ fs.rmSync(outPath, { force: true });
261
+ }
262
+ await writeTarGz(outPath, stagingRoot, pluginId);
263
+ return outPath;
264
+ }
265
+ finally {
266
+ fs.rmSync(stagingRoot, { recursive: true, force: true });
267
+ }
268
+ }
269
+ exports.__private = {
270
+ ICON_EXTENSIONS,
271
+ copyIcon,
272
+ readManifest,
273
+ rejectNativeAddonsRecursive,
274
+ uniqueStagingDir,
275
+ validateDeclaredModuleExec,
276
+ writeTarGz,
277
+ };
@@ -0,0 +1,5 @@
1
+ export declare function isPathInside(rootPath: string, candidatePath: string): boolean;
2
+ export declare function rejectSymlinksRecursive(rootDir: string): void;
3
+ export declare function ensureDirectory(filePath: string): void;
4
+ export declare function copyFileStrict(sourcePath: string, destinationPath: string): void;
5
+ export declare function copyDirectoryRecursiveStrict(sourceDir: string, destinationDir: string): void;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPathInside = isPathInside;
4
+ exports.rejectSymlinksRecursive = rejectSymlinksRecursive;
5
+ exports.ensureDirectory = ensureDirectory;
6
+ exports.copyFileStrict = copyFileStrict;
7
+ exports.copyDirectoryRecursiveStrict = copyDirectoryRecursiveStrict;
8
+ const fs = require("node:fs");
9
+ const path = require("node:path");
10
+ function isPathInside(rootPath, candidatePath) {
11
+ const relative = path.relative(rootPath, candidatePath);
12
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
13
+ }
14
+ function rejectSymlinksRecursive(rootDir) {
15
+ const stack = [rootDir];
16
+ while (stack.length > 0) {
17
+ const current = stack.pop();
18
+ if (!current) {
19
+ continue;
20
+ }
21
+ const entries = fs.readdirSync(current, { withFileTypes: true });
22
+ for (const entry of entries) {
23
+ const entryPath = path.join(current, entry.name);
24
+ const stats = fs.lstatSync(entryPath);
25
+ if (stats.isSymbolicLink()) {
26
+ throw new Error(`plugin contains a symlink: ${entryPath}`);
27
+ }
28
+ if (stats.isDirectory()) {
29
+ stack.push(entryPath);
30
+ }
31
+ }
32
+ }
33
+ }
34
+ function ensureDirectory(filePath) {
35
+ fs.mkdirSync(filePath, { recursive: true });
36
+ }
37
+ function copyFileStrict(sourcePath, destinationPath) {
38
+ const stats = fs.lstatSync(sourcePath);
39
+ if (stats.isSymbolicLink()) {
40
+ throw new Error(`plugin contains a symlink: ${sourcePath}`);
41
+ }
42
+ if (!stats.isFile()) {
43
+ throw new Error(`expected file: ${sourcePath}`);
44
+ }
45
+ ensureDirectory(path.dirname(destinationPath));
46
+ fs.copyFileSync(sourcePath, destinationPath);
47
+ }
48
+ function copyDirectoryRecursiveStrict(sourceDir, destinationDir) {
49
+ if (!fs.existsSync(sourceDir)) {
50
+ return;
51
+ }
52
+ const stats = fs.lstatSync(sourceDir);
53
+ if (stats.isSymbolicLink()) {
54
+ throw new Error(`plugin contains a symlink: ${sourceDir}`);
55
+ }
56
+ if (!stats.isDirectory()) {
57
+ throw new Error(`expected directory: ${sourceDir}`);
58
+ }
59
+ ensureDirectory(destinationDir);
60
+ const entries = fs.readdirSync(sourceDir, { withFileTypes: true });
61
+ for (const entry of entries) {
62
+ const sourcePath = path.join(sourceDir, entry.name);
63
+ const destinationPath = path.join(destinationDir, entry.name);
64
+ const entryStats = fs.lstatSync(sourcePath);
65
+ if (entryStats.isSymbolicLink()) {
66
+ throw new Error(`plugin contains a symlink: ${sourcePath}`);
67
+ }
68
+ if (entryStats.isDirectory()) {
69
+ copyDirectoryRecursiveStrict(sourcePath, destinationPath);
70
+ continue;
71
+ }
72
+ if (entryStats.isFile()) {
73
+ fs.copyFileSync(sourcePath, destinationPath);
74
+ }
75
+ }
76
+ }
package/lib/init.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ interface InitCommandError {
2
+ code?: string;
3
+ }
4
+ export declare function initUsage(commandName?: string): string;
5
+ export declare function runInitCommand(args: string[]): Promise<string>;
6
+ export declare function isUsageError(error: unknown): error is InitCommandError;
7
+ export {};