esm.dev 1.7.4 → 1.8.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 +1 -1
- package/package.json +16 -8
- package/dist/cli.js +0 -20
- package/dist/commands/ESMDevCommand.js +0 -6
- package/dist/commands/InitCommand.js +0 -50
- package/dist/commands/LoginCommand.js +0 -12
- package/dist/commands/MustacheGeneratorCommand.js +0 -9
- package/dist/commands/RepublishCommand.js +0 -11
- package/dist/commands/StartCommand.js +0 -16
- package/dist/commands/TokenCommand.js +0 -20
- package/dist/commands/VersionCommand.js +0 -13
- package/dist/commands/WaitForRegistryCommand.js +0 -12
- package/dist/commands/WatchCommand.js +0 -12
- package/dist/commands/mixins/CommandClass.js +0 -1
- package/dist/commands/mixins/ESMServed.js +0 -9
- package/dist/commands/mixins/ESMStorageSpecific.js +0 -9
- package/dist/commands/mixins/PackagePathSpecific.js +0 -14
- package/dist/commands/mixins/RegistrySpecific.js +0 -9
- package/dist/commands/mixins/Retryable.js +0 -28
- package/dist/commands/mixins/Servable.js +0 -11
- package/dist/commands/mixins/Watchable.js +0 -9
- package/dist/lib/MustacheGenerator.js +0 -9
- package/dist/lib/getPackageMeta.js +0 -10
- package/dist/lib/login.js +0 -31
- package/dist/lib/publish.js +0 -7
- package/dist/lib/queue.js +0 -41
- package/dist/lib/republish.js +0 -9
- package/dist/lib/server.js +0 -33
- package/dist/lib/unpublish.js +0 -25
- package/dist/lib/until.js +0 -16
- package/dist/lib/watch.js +0 -72
- package/dist/options/EnvOption.js +0 -6
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ It expects you to have a local version of ESM.sh and verdaccio running. It will
|
|
|
10
10
|
|
|
11
11
|
- You have [docker](https://www.docker.com/) installed
|
|
12
12
|
- You have [docker compose](https://docs.docker.com/compose/) installed
|
|
13
|
-
- You have a JavaScript runtime installed
|
|
13
|
+
- You have a JavaScript runtime installed, EG: [Node.js](https://nodejs.org/)
|
|
14
14
|
|
|
15
15
|
### Installation
|
|
16
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esm.dev",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "TypeScript library template",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"esm.dev": "./dist/cli.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
14
|
+
"build": "npm run clean && tsc",
|
|
15
15
|
"clean": "rimraf dist",
|
|
16
|
-
"esm.dev": "
|
|
16
|
+
"esm.dev": "node --experimental-strip-types --no-warnings=ExperimentalWarning ./src/cli.ts",
|
|
17
17
|
"prepare": "husky",
|
|
18
18
|
"start": "docker compose up --detach --remove-orphans",
|
|
19
|
-
"stop": "docker compose down"
|
|
19
|
+
"stop": "docker compose down",
|
|
20
|
+
"test": "vitest run"
|
|
20
21
|
},
|
|
21
22
|
"repository": {
|
|
22
23
|
"type": "git",
|
|
@@ -33,21 +34,22 @@
|
|
|
33
34
|
"@commitlint/cli": "19.8.1",
|
|
34
35
|
"@commitlint/config-conventional": "19.8.1",
|
|
35
36
|
"@commitlint/types": "19.8.1",
|
|
36
|
-
"@types/bun": "latest",
|
|
37
37
|
"@types/http-proxy": "^1.17.16",
|
|
38
38
|
"@types/lodash.debounce": "^4.0.9",
|
|
39
39
|
"@types/mustache": "^4.2.6",
|
|
40
|
+
"@types/node": "^22.15.27",
|
|
40
41
|
"@types/ramda": "^0.30.2",
|
|
41
42
|
"husky": "9.1.7",
|
|
42
|
-
"lint-staged": "16.
|
|
43
|
+
"lint-staged": "16.1.0",
|
|
43
44
|
"prettier": "3.5.3",
|
|
44
45
|
"rimraf": "6.0.1",
|
|
45
46
|
"semantic-release": "^24.2.4",
|
|
46
|
-
"typescript": "5.8.3"
|
|
47
|
+
"typescript": "5.8.3",
|
|
48
|
+
"vitest": "^3.1.4"
|
|
47
49
|
},
|
|
48
50
|
"lint-staged": {
|
|
49
51
|
"*.{md,json,js,jsx,ts,tsx,yml,yaml}": [
|
|
50
|
-
"
|
|
52
|
+
"npx prettier --ignore-path .gitignore --write"
|
|
51
53
|
]
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
@@ -56,7 +58,10 @@
|
|
|
56
58
|
"escape-string-regexp": "^5.0.0",
|
|
57
59
|
"glob": "^11.0.2",
|
|
58
60
|
"http-proxy": "^1.18.1",
|
|
61
|
+
"ignore": "^7.0.4",
|
|
59
62
|
"lodash.debounce": "^4.0.8",
|
|
63
|
+
"minimatch": "^10.0.1",
|
|
64
|
+
"minipass": "^7.1.2",
|
|
60
65
|
"mustache": "^4.2.0",
|
|
61
66
|
"npm": "^11.4.1",
|
|
62
67
|
"ramda": "^0.30.1",
|
|
@@ -65,5 +70,8 @@
|
|
|
65
70
|
"typanion": "^3.14.0",
|
|
66
71
|
"zod": "^3.25.23",
|
|
67
72
|
"zx": "^8.5.4"
|
|
73
|
+
},
|
|
74
|
+
"optionalDependencies": {
|
|
75
|
+
"@rollup/rollup-linux-x64-musl": "^4.41.1"
|
|
68
76
|
}
|
|
69
77
|
}
|
package/dist/cli.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { runExit } from 'clipanion';
|
|
3
|
-
import { WatchCommand } from './commands/WatchCommand.js';
|
|
4
|
-
import { RepublishCommand } from './commands/RepublishCommand.js';
|
|
5
|
-
import { LoginCommand } from './commands/LoginCommand.js';
|
|
6
|
-
import { TokenCommand } from './commands/TokenCommand.js';
|
|
7
|
-
import { WaitForRegistryCommand } from './commands/WaitForRegistryCommand.js';
|
|
8
|
-
import { StartCommand } from './commands/StartCommand.js';
|
|
9
|
-
import { InitCommand } from './commands/InitCommand.js';
|
|
10
|
-
import { VersionCommand } from './commands/VersionCommand.js';
|
|
11
|
-
runExit([
|
|
12
|
-
InitCommand,
|
|
13
|
-
LoginCommand,
|
|
14
|
-
TokenCommand,
|
|
15
|
-
RepublishCommand,
|
|
16
|
-
StartCommand,
|
|
17
|
-
VersionCommand,
|
|
18
|
-
WaitForRegistryCommand,
|
|
19
|
-
WatchCommand,
|
|
20
|
-
]);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
import { RegistrySpecific } from './mixins/RegistrySpecific.js';
|
|
3
|
-
import { ESMStorageSpecific } from './mixins/ESMStorageSpecific.js';
|
|
4
|
-
import { PackagePathSpecific } from './mixins/PackagePathSpecific.js';
|
|
5
|
-
export class ESMDevCommand extends ESMStorageSpecific(RegistrySpecific(PackagePathSpecific(Command))) {
|
|
6
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ESMDevCommand } from './ESMDevCommand.js';
|
|
2
|
-
import { PackagePathSpecific } from './mixins/PackagePathSpecific.js';
|
|
3
|
-
import { MustacheGeneratorCommand } from './MustacheGeneratorCommand.js';
|
|
4
|
-
import { Option } from 'clipanion';
|
|
5
|
-
import { isNumber } from 'typanion';
|
|
6
|
-
export class InitCommand extends PackagePathSpecific(MustacheGeneratorCommand) {
|
|
7
|
-
static paths = [['init']];
|
|
8
|
-
static usage = ESMDevCommand.Usage({
|
|
9
|
-
description: 'Initialises your repo ready to work with ESM.sh locally',
|
|
10
|
-
examples: [
|
|
11
|
-
['Create a minimal template', 'esm.dev init'],
|
|
12
|
-
["Specify the packages you're developing", 'esm.dev init packages/*'],
|
|
13
|
-
[
|
|
14
|
-
'Specify different ports',
|
|
15
|
-
'esm.dev init --port 3001 --esm-port 8081 --registry-port 4444',
|
|
16
|
-
],
|
|
17
|
-
],
|
|
18
|
-
});
|
|
19
|
-
esmPort = Option.String('-e,--esm-port', '8080', {
|
|
20
|
-
description: 'The port of the ESM Server',
|
|
21
|
-
validator: isNumber(),
|
|
22
|
-
});
|
|
23
|
-
esmStoragePath = Option.String('-s,--esm-storage-path', './docker-storage/esm/esmd', {
|
|
24
|
-
description: "Path to ESM.sh's storage",
|
|
25
|
-
});
|
|
26
|
-
port = Option.String('-p,--port', '3000', {
|
|
27
|
-
description: "The server's port",
|
|
28
|
-
});
|
|
29
|
-
outputDirectory = Option.String('-o,--output-dir', '.', {
|
|
30
|
-
description: 'The output directory',
|
|
31
|
-
});
|
|
32
|
-
registryPort = Option.String('-r,--registry-port', '4873', {
|
|
33
|
-
description: 'The port of your local registry',
|
|
34
|
-
validator: isNumber(),
|
|
35
|
-
});
|
|
36
|
-
esmURL;
|
|
37
|
-
npmRegistryURL;
|
|
38
|
-
packages;
|
|
39
|
-
async execute() {
|
|
40
|
-
const path = await import('node:path');
|
|
41
|
-
this.templateDir = path.resolve(import.meta.dirname, '..', '..', 'templates', 'init');
|
|
42
|
-
this.destinationDir = this.outputDirectory;
|
|
43
|
-
this.packages = this.packagePaths.map((packagePath) => ({
|
|
44
|
-
path: packagePath,
|
|
45
|
-
basename: path.basename(packagePath),
|
|
46
|
-
}));
|
|
47
|
-
await this.removeDestinationFile('docker-compose.yaml', 'docker-compose.yml.mustache');
|
|
48
|
-
await super.execute();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
import { RegistrySpecific } from './mixins/RegistrySpecific.js';
|
|
3
|
-
export class LoginCommand extends RegistrySpecific(Command) {
|
|
4
|
-
static paths = [['login']];
|
|
5
|
-
static usage = Command.Usage({
|
|
6
|
-
description: 'Login in to the NPM registry',
|
|
7
|
-
});
|
|
8
|
-
async execute() {
|
|
9
|
-
const { login } = await import('../lib/login.js');
|
|
10
|
-
return login(this.registry);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { GeneratorCommand } from 'clipanion-generator-command';
|
|
2
|
-
import { MustacheGenerator } from '../lib/MustacheGenerator.js';
|
|
3
|
-
export class MustacheGeneratorCommand extends GeneratorCommand {
|
|
4
|
-
get generator() {
|
|
5
|
-
return new MustacheGenerator(this.templateDir, this.destinationDir, [
|
|
6
|
-
'.mustache',
|
|
7
|
-
]);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ESMDevCommand } from './ESMDevCommand.js';
|
|
2
|
-
export class RepublishCommand extends ESMDevCommand {
|
|
3
|
-
static paths = [['republish']];
|
|
4
|
-
static usage = ESMDevCommand.Usage({
|
|
5
|
-
description: 'Removes the references, of given packages, from the ESM server and registry and republishes.',
|
|
6
|
-
});
|
|
7
|
-
async execute() {
|
|
8
|
-
const { republish } = await import('../lib/republish.js');
|
|
9
|
-
await this.eachPackagePath((packagePath) => republish(packagePath, this));
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ESMDevCommand } from './ESMDevCommand.js';
|
|
2
|
-
import { Servable } from './mixins/Servable.js';
|
|
3
|
-
import { Watchable } from './mixins/Watchable.js';
|
|
4
|
-
import { ESMServed } from './mixins/ESMServed.js';
|
|
5
|
-
export class StartCommand extends Servable(Watchable(ESMServed(ESMDevCommand))) {
|
|
6
|
-
static paths = [['start']];
|
|
7
|
-
static usage = ESMDevCommand.Usage({
|
|
8
|
-
description: 'Runs a server and concurrently watches a file system',
|
|
9
|
-
});
|
|
10
|
-
async execute() {
|
|
11
|
-
const { watch } = await import('../lib/watch.js');
|
|
12
|
-
const { serve } = await import('../lib/server.js');
|
|
13
|
-
serve(this.port, this.esmOrigin);
|
|
14
|
-
await this.eachPackagePath((packagePath) => watch(packagePath, this));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
import { RegistrySpecific } from './mixins/RegistrySpecific.js';
|
|
3
|
-
export class TokenCommand extends RegistrySpecific(Command) {
|
|
4
|
-
static paths = [['token']];
|
|
5
|
-
static usage = Command.Usage({
|
|
6
|
-
description: 'Get the NPM token',
|
|
7
|
-
});
|
|
8
|
-
async execute() {
|
|
9
|
-
const { default: escapeStringRegexp } = await import('escape-string-regexp');
|
|
10
|
-
const npmrc = await Bun.file(`~/.npmrc`).text();
|
|
11
|
-
const url = new URL(this.registry);
|
|
12
|
-
const regex = new RegExp(`^//${escapeStringRegexp(url.hostname)}/:_authToken=(.*)$`, 'm');
|
|
13
|
-
const match = regex.exec(npmrc);
|
|
14
|
-
if (!match) {
|
|
15
|
-
this.context.stderr.write(`Token has not been created yet\n`);
|
|
16
|
-
return 1;
|
|
17
|
-
}
|
|
18
|
-
this.context.stdout.write(match[1] + '\n');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
export class VersionCommand extends Command {
|
|
4
|
-
static paths = [['version']];
|
|
5
|
-
static usage = Command.Usage({
|
|
6
|
-
description: 'Display the version of esm.dev',
|
|
7
|
-
});
|
|
8
|
-
async execute() {
|
|
9
|
-
const path = await import('node:path');
|
|
10
|
-
const pckg = JSON.parse(await readFile(path.resolve(import.meta.dirname, '..', '..', 'package.json'), 'utf-8'));
|
|
11
|
-
this.context.stdout.write(`${pckg.version}\n`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
import { RegistrySpecific } from './mixins/RegistrySpecific.js';
|
|
3
|
-
import { Retryable } from './mixins/Retryable.js';
|
|
4
|
-
export class WaitForRegistryCommand extends Retryable(RegistrySpecific(Command)) {
|
|
5
|
-
static paths = [['wait-for-registry'], ['wfr']];
|
|
6
|
-
static usage = Command.Usage({
|
|
7
|
-
description: 'wait for the registry to be online',
|
|
8
|
-
});
|
|
9
|
-
async execute() {
|
|
10
|
-
return this.retry(this.registry);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ESMDevCommand } from './ESMDevCommand.js';
|
|
2
|
-
import { Watchable } from './mixins/Watchable.js';
|
|
3
|
-
export class WatchCommand extends Watchable(ESMDevCommand) {
|
|
4
|
-
static paths = [['watch']];
|
|
5
|
-
static usage = ESMDevCommand.Usage({
|
|
6
|
-
description: 'Watches directories and republishes on changes',
|
|
7
|
-
});
|
|
8
|
-
async execute() {
|
|
9
|
-
const { watch } = await import('../lib/watch.js');
|
|
10
|
-
await this.eachPackagePath((packagePath) => watch(packagePath, this));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EnvOption } from '../../options/EnvOption.js';
|
|
2
|
-
export function ESMServed(Base) {
|
|
3
|
-
class ESMServed extends Base {
|
|
4
|
-
esmOrigin = EnvOption('ESM_ORIGIN', '-e,--esm-origin', {
|
|
5
|
-
description: 'The base URL of the ESM Server',
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
return ESMServed;
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EnvOption } from '../../options/EnvOption.js';
|
|
2
|
-
export function ESMStorageSpecific(Base) {
|
|
3
|
-
class ESMStorageSpecific extends Base {
|
|
4
|
-
esmStoragePath = EnvOption('ESM_STORAGE_PATH', '-s,--esm-storage-path', {
|
|
5
|
-
description: "Path to ESM.sh's storage",
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
return ESMStorageSpecific;
|
|
9
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Option } from 'clipanion';
|
|
2
|
-
export function PackagePathSpecific(Base) {
|
|
3
|
-
class PackagePathSpecific extends Base {
|
|
4
|
-
packagePaths = Option.Rest({
|
|
5
|
-
name: 'packages',
|
|
6
|
-
});
|
|
7
|
-
async eachPackagePath(cb) {
|
|
8
|
-
const { glob } = await import('glob');
|
|
9
|
-
const packagePaths = (await Promise.all(this.packagePaths.map((packagePath) => glob(packagePath)))).flat();
|
|
10
|
-
await Promise.all(packagePaths.map(cb));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return PackagePathSpecific;
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EnvOption } from '../../options/EnvOption.js';
|
|
2
|
-
export function RegistrySpecific(Base) {
|
|
3
|
-
class RegistrySpecific extends Base {
|
|
4
|
-
registry = EnvOption('NPM_REGISTRY', '-r,--registry', {
|
|
5
|
-
description: 'The URL of your local registry',
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
return RegistrySpecific;
|
|
9
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Option } from 'clipanion';
|
|
2
|
-
import { isNumber } from 'typanion';
|
|
3
|
-
export function Retryable(Base) {
|
|
4
|
-
class Retryable extends Base {
|
|
5
|
-
timeout = Option.String('-t,--timeout', '10000', {
|
|
6
|
-
description: 'The amount of total ms to keep trying for',
|
|
7
|
-
validator: isNumber(),
|
|
8
|
-
});
|
|
9
|
-
interval = Option.String('-i,--interval', '300', {
|
|
10
|
-
description: 'The amount of ms inbetween each attempt',
|
|
11
|
-
validator: isNumber(),
|
|
12
|
-
});
|
|
13
|
-
async retry(endpoint) {
|
|
14
|
-
const { until } = await import('../../lib/until.js');
|
|
15
|
-
if (!(await until({
|
|
16
|
-
...this,
|
|
17
|
-
try: async (signal) => {
|
|
18
|
-
const response = await fetch(endpoint, { signal });
|
|
19
|
-
return response.ok;
|
|
20
|
-
},
|
|
21
|
-
}))) {
|
|
22
|
-
this.context.stderr.write(`${endpoint} is not available\n`);
|
|
23
|
-
return 1;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return Retryable;
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { isNumber } from 'typanion';
|
|
2
|
-
import { EnvOption } from '../../options/EnvOption.js';
|
|
3
|
-
export function Servable(Base) {
|
|
4
|
-
class Servable extends Base {
|
|
5
|
-
port = EnvOption('PORT', '-p,--port', {
|
|
6
|
-
description: 'The port to run the server on',
|
|
7
|
-
validator: isNumber(),
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
return Servable;
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Option } from 'clipanion';
|
|
2
|
-
export function Watchable(Base) {
|
|
3
|
-
class Watchable extends Base {
|
|
4
|
-
legacyMethod = Option.Boolean('-l,--legacy-method', false, {
|
|
5
|
-
description: 'Use a less performant, legacy, watch method. Sometimes needed in docker or vagrant environments.',
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
return Watchable;
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Mustache from 'mustache';
|
|
2
|
-
import { Generator } from 'clipanion-generator-command/Generator';
|
|
3
|
-
export class MustacheGenerator extends Generator {
|
|
4
|
-
renderTemplate(templateContext, template) {
|
|
5
|
-
return Mustache.render(template, templateContext, undefined, {
|
|
6
|
-
escape: (x) => x,
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { readFile, stat as getStat } from 'node:fs/promises';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
export async function getPackageMeta(packagePath) {
|
|
4
|
-
const stat = await getStat(packagePath);
|
|
5
|
-
const packageRoot = stat.isDirectory()
|
|
6
|
-
? packagePath
|
|
7
|
-
: path.dirname(packagePath);
|
|
8
|
-
const pckg = JSON.parse(await readFile(path.join(packageRoot, 'package.json'), 'utf-8'));
|
|
9
|
-
return { name: pckg.name, packageRoot, private: pckg.private };
|
|
10
|
-
}
|
package/dist/lib/login.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
export function login(registry) {
|
|
3
|
-
return new Promise((resolve) => {
|
|
4
|
-
const child = spawn('bunx', [
|
|
5
|
-
'npm',
|
|
6
|
-
'login',
|
|
7
|
-
'--registry',
|
|
8
|
-
registry,
|
|
9
|
-
'--quiet',
|
|
10
|
-
]);
|
|
11
|
-
child.stderr.on('data', (d) => console.error(d.toString()));
|
|
12
|
-
child.stdout.on('data', (d) => {
|
|
13
|
-
const data = d.toString();
|
|
14
|
-
switch (true) {
|
|
15
|
-
case /username/i.test(data):
|
|
16
|
-
child.stdin.write('esm.dev\n');
|
|
17
|
-
break;
|
|
18
|
-
case /password/i.test(data):
|
|
19
|
-
child.stdin.write('esm.dev\n');
|
|
20
|
-
break;
|
|
21
|
-
case /email/i.test(data):
|
|
22
|
-
child.stdin.write('esm.dev@esm.dev.com');
|
|
23
|
-
break;
|
|
24
|
-
case /logged in as/i.test(data):
|
|
25
|
-
child.stdin.end();
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
child.on('exit', resolve);
|
|
30
|
-
});
|
|
31
|
-
}
|
package/dist/lib/publish.js
DELETED
package/dist/lib/queue.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import debounce from 'lodash.debounce';
|
|
2
|
-
import throat from 'throat';
|
|
3
|
-
export async function queue(signal, fn) {
|
|
4
|
-
return _queue((...args) => {
|
|
5
|
-
signal.throwIfAborted();
|
|
6
|
-
return fn(...args);
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
const _queue = throat.default(1);
|
|
10
|
-
/**
|
|
11
|
-
* Just like debounce, but the first call will add a promise to the queue
|
|
12
|
-
* and that promise won't resolve until the debounced function is finally called.
|
|
13
|
-
*/
|
|
14
|
-
export function queuedDebounce(fn, delay, signal) {
|
|
15
|
-
let promiseWithResolvers;
|
|
16
|
-
signal.addEventListener('abort', (reason) => promiseWithResolvers?.reject(reason));
|
|
17
|
-
const debounced = debounce(async (...args) => {
|
|
18
|
-
try {
|
|
19
|
-
const result = await fn(...args);
|
|
20
|
-
promiseWithResolvers?.resolve(result);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
promiseWithResolvers?.reject(error);
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
promiseWithResolvers = undefined;
|
|
27
|
-
}
|
|
28
|
-
}, delay);
|
|
29
|
-
return (...args) => {
|
|
30
|
-
const { promise } = start();
|
|
31
|
-
debounced(...args);
|
|
32
|
-
return promise;
|
|
33
|
-
};
|
|
34
|
-
function start() {
|
|
35
|
-
if (!promiseWithResolvers) {
|
|
36
|
-
promiseWithResolvers = Promise.withResolvers();
|
|
37
|
-
queue(signal, async () => promiseWithResolvers?.promise);
|
|
38
|
-
}
|
|
39
|
-
return promiseWithResolvers;
|
|
40
|
-
}
|
|
41
|
-
}
|
package/dist/lib/republish.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { getPackageMeta } from './getPackageMeta.js';
|
|
2
|
-
import { publish } from './publish.js';
|
|
3
|
-
import { unpublish } from './unpublish.js';
|
|
4
|
-
export async function republish(packagePath, opts) {
|
|
5
|
-
console.info(`Republishing ${packagePath}`);
|
|
6
|
-
const { name, packageRoot } = await getPackageMeta(packagePath);
|
|
7
|
-
await unpublish({ ...opts, name });
|
|
8
|
-
await publish({ ...opts, packageRoot });
|
|
9
|
-
}
|
package/dist/lib/server.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { queue } from './queue.js';
|
|
2
|
-
import { createServer } from 'node:http';
|
|
3
|
-
import httpProxy from 'http-proxy';
|
|
4
|
-
import { addAbortSignal } from 'node:stream';
|
|
5
|
-
export function serve(port, esmOrigin) {
|
|
6
|
-
const proxy = httpProxy.createProxyServer();
|
|
7
|
-
const abortController = new AbortController();
|
|
8
|
-
const signal = abortController.signal;
|
|
9
|
-
const server = createServer((req, res) => {
|
|
10
|
-
queue(signal, () => new Promise((resolve, reject) => {
|
|
11
|
-
console.info('Proxying', req.url);
|
|
12
|
-
addAbortSignal(signal, req);
|
|
13
|
-
addAbortSignal(signal, res);
|
|
14
|
-
req.on('error', reject);
|
|
15
|
-
res.on('error', reject);
|
|
16
|
-
res.on('close', resolve);
|
|
17
|
-
proxy.web(req, res, { target: esmOrigin });
|
|
18
|
-
})).catch((error) => {
|
|
19
|
-
res.statusCode = 500;
|
|
20
|
-
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
21
|
-
res.write(JSON.stringify(error));
|
|
22
|
-
res.end();
|
|
23
|
-
});
|
|
24
|
-
}).listen(port, () => {
|
|
25
|
-
console.info('ESM proxy server listining on', server.address());
|
|
26
|
-
});
|
|
27
|
-
return () => {
|
|
28
|
-
console.info('closing the server');
|
|
29
|
-
abortController.abort();
|
|
30
|
-
server.closeAllConnections();
|
|
31
|
-
server.close();
|
|
32
|
-
};
|
|
33
|
-
}
|
package/dist/lib/unpublish.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { $, ProcessOutput } from 'zx';
|
|
2
|
-
import { glob } from 'glob';
|
|
3
|
-
import { rm } from 'node:fs/promises';
|
|
4
|
-
export async function unpublish({ registry, esmStoragePath, name, }) {
|
|
5
|
-
await Promise.all([
|
|
6
|
-
unpublishPackage(registry, name),
|
|
7
|
-
deleteESMCache(esmStoragePath, name),
|
|
8
|
-
]);
|
|
9
|
-
}
|
|
10
|
-
async function unpublishPackage(registry, name) {
|
|
11
|
-
try {
|
|
12
|
-
await $ `bunx npm unpublish --registry ${registry} --force ${name}`;
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
if (error instanceof ProcessOutput &&
|
|
16
|
-
!error.stderr.includes('npm error code E404'))
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async function deleteESMCache(esmStoragePath, name) {
|
|
21
|
-
await glob(`${esmStoragePath}/**/${name}@*`).then((paths) => Promise.all(paths.map((path) => {
|
|
22
|
-
console.info('Deleting', path);
|
|
23
|
-
return rm(path, { recursive: true });
|
|
24
|
-
})));
|
|
25
|
-
}
|
package/dist/lib/until.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises';
|
|
2
|
-
export async function until({ interval, timeout, try: Try, }) {
|
|
3
|
-
const signal = AbortSignal.timeout(timeout);
|
|
4
|
-
while (!signal.aborted) {
|
|
5
|
-
try {
|
|
6
|
-
if (await Try(signal))
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
catch (error) { }
|
|
10
|
-
try {
|
|
11
|
-
await setTimeout(interval, { signal });
|
|
12
|
-
}
|
|
13
|
-
catch (error) { }
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
package/dist/lib/watch.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { watch as fsWatch, watchFile } from 'node:fs';
|
|
2
|
-
import { republish } from './republish.js';
|
|
3
|
-
import { getPackageMeta } from './getPackageMeta.js';
|
|
4
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
5
|
-
import { createHash } from 'node:crypto';
|
|
6
|
-
import { glob } from 'glob';
|
|
7
|
-
import { queue, queuedDebounce } from './queue.js';
|
|
8
|
-
export async function watch(packagePath, opts) {
|
|
9
|
-
const { name, packageRoot, private: prvte, } = await getPackageMeta(packagePath);
|
|
10
|
-
if (prvte) {
|
|
11
|
-
console.info(`${name} is a private package... ignoring`);
|
|
12
|
-
return () => { };
|
|
13
|
-
}
|
|
14
|
-
console.info('Watching', packagePath);
|
|
15
|
-
const abortController = new AbortController();
|
|
16
|
-
const signal = abortController.signal;
|
|
17
|
-
const republishPackage = () => republish(packagePath, opts).catch(console.error);
|
|
18
|
-
const debounceRepublish = queuedDebounce((filename = '') => {
|
|
19
|
-
console.info(`Change detected at ${packagePath}/${filename}`);
|
|
20
|
-
return republishPackage();
|
|
21
|
-
}, 1_000, signal);
|
|
22
|
-
await queue(signal, republishPackage);
|
|
23
|
-
if (opts.legacyMethod) {
|
|
24
|
-
const close = await legacyWatch(packagePath, () => debounceRepublish());
|
|
25
|
-
return () => {
|
|
26
|
-
console.info('stop watching');
|
|
27
|
-
close();
|
|
28
|
-
abortController.abort();
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const watcher = fsWatch(packageRoot, { recursive: true }, (_, filename) => debounceRepublish(filename ?? ''));
|
|
33
|
-
return () => {
|
|
34
|
-
console.info('stop watching');
|
|
35
|
-
watcher.close();
|
|
36
|
-
abortController.abort();
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function legacyWatch(dirname, cb) {
|
|
41
|
-
const filename = await hashDirectory(dirname);
|
|
42
|
-
const watcher = watchFile(filename, cb);
|
|
43
|
-
let timer;
|
|
44
|
-
beginTimer();
|
|
45
|
-
return () => {
|
|
46
|
-
watcher.unref();
|
|
47
|
-
clearTimeout(timer);
|
|
48
|
-
};
|
|
49
|
-
function beginTimer() {
|
|
50
|
-
timer = setTimeout(() => hashDirectory(dirname).catch(console.error).finally(beginTimer), 1_000);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async function hashDirectory(dirname) {
|
|
54
|
-
const filename = `/tmp/${dirname.replace(/\//g, '-')}.hash.txt`;
|
|
55
|
-
const files = await glob(`${dirname}/**/*`, { nodir: true });
|
|
56
|
-
const hashes = await Promise.all(files.map(async (file) => {
|
|
57
|
-
const contents = await readFile(file, 'utf-8');
|
|
58
|
-
return createHash('sha256').update(contents).digest('hex');
|
|
59
|
-
}));
|
|
60
|
-
const newHash = hashes.join('');
|
|
61
|
-
let previousHash = '';
|
|
62
|
-
try {
|
|
63
|
-
previousHash = await readFile(filename, 'utf-8');
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
if (error.code !== 'ENOENT')
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
if (newHash !== previousHash)
|
|
70
|
-
await writeFile(filename, newHash);
|
|
71
|
-
return filename;
|
|
72
|
-
}
|