esm.dev 2.0.4 → 2.0.6

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.
Files changed (64) hide show
  1. package/dist/cli.js +20 -0
  2. package/dist/commands/ESMDevCommand.js +6 -0
  3. package/dist/commands/InitCommand.js +49 -0
  4. package/dist/commands/LoginCommand.js +12 -0
  5. package/dist/commands/MustacheGeneratorCommand.js +9 -0
  6. package/dist/commands/RepublishCommand.js +11 -0
  7. package/dist/commands/StartCommand.js +18 -0
  8. package/dist/commands/TokenCommand.js +23 -0
  9. package/dist/commands/VersionCommand.js +15 -0
  10. package/dist/commands/WaitForRegistryCommand.js +12 -0
  11. package/dist/commands/WatchCommand.js +12 -0
  12. package/dist/commands/mixins/CommandClass.js +1 -0
  13. package/dist/commands/mixins/ESMServed.js +9 -0
  14. package/dist/commands/mixins/ESMStorageSpecific.js +9 -0
  15. package/dist/commands/mixins/PackagePathSpecific.js +14 -0
  16. package/dist/commands/mixins/RegistrySpecific.js +9 -0
  17. package/dist/commands/mixins/Retryable.js +29 -0
  18. package/dist/commands/mixins/Servable.js +11 -0
  19. package/dist/commands/mixins/Watchable.js +9 -0
  20. package/dist/commands/options/EnvOption.js +6 -0
  21. package/dist/lib/MustacheGenerator.js +9 -0
  22. package/dist/lib/getPackageMeta.js +10 -0
  23. package/dist/lib/index.js +8 -0
  24. package/dist/lib/login.js +25 -0
  25. package/dist/lib/publish.js +7 -0
  26. package/dist/lib/queue.js +48 -0
  27. package/dist/lib/republish.js +9 -0
  28. package/dist/lib/server.js +34 -0
  29. package/dist/lib/unpublish.js +26 -0
  30. package/dist/lib/until.js +32 -0
  31. package/dist/lib/watch.js +88 -0
  32. package/dist/lib/watchIgnoreList.js +50 -0
  33. package/package.json +3 -3
  34. package/src/cli.ts +0 -21
  35. package/src/commands/ESMDevCommand.ts +0 -8
  36. package/src/commands/InitCommand.ts +0 -71
  37. package/src/commands/LoginCommand.ts +0 -15
  38. package/src/commands/MustacheGeneratorCommand.ts +0 -10
  39. package/src/commands/RepublishCommand.ts +0 -15
  40. package/src/commands/StartCommand.ts +0 -23
  41. package/src/commands/TokenCommand.ts +0 -29
  42. package/src/commands/VersionCommand.ts +0 -23
  43. package/src/commands/WaitForRegistryCommand.ts +0 -17
  44. package/src/commands/WatchCommand.ts +0 -15
  45. package/src/commands/mixins/CommandClass.ts +0 -3
  46. package/src/commands/mixins/ESMServed.ts +0 -12
  47. package/src/commands/mixins/ESMStorageSpecific.ts +0 -16
  48. package/src/commands/mixins/PackagePathSpecific.ts +0 -18
  49. package/src/commands/mixins/RegistrySpecific.ts +0 -12
  50. package/src/commands/mixins/Retryable.ts +0 -33
  51. package/src/commands/mixins/Servable.ts +0 -14
  52. package/src/commands/mixins/Watchable.ts +0 -13
  53. package/src/commands/options/EnvOption.ts +0 -27
  54. package/src/lib/MustacheGenerator.ts +0 -10
  55. package/src/lib/getPackageMeta.ts +0 -15
  56. package/src/lib/login.ts +0 -29
  57. package/src/lib/publish.ts +0 -14
  58. package/src/lib/queue.ts +0 -65
  59. package/src/lib/republish.ts +0 -16
  60. package/src/lib/server.ts +0 -43
  61. package/src/lib/unpublish.ts +0 -40
  62. package/src/lib/until.ts +0 -50
  63. package/src/lib/watch.ts +0 -138
  64. package/src/lib/watchIgnoreList.ts +0 -61
@@ -0,0 +1,50 @@
1
+ import gitignore from 'ignore';
2
+ import { Minimatch } from 'minimatch';
3
+ import { createReadStream } from 'node:fs';
4
+ import { access, constants } from 'node:fs/promises';
5
+ import * as path from 'node:path';
6
+ import { createInterface as createReadlineInterface } from 'node:readline/promises';
7
+ export async function getWatchIgnorer(dirname) {
8
+ const ignoreList = await getIgnoreList(dirname);
9
+ return ignoreList?.basename === '.gitignore'
10
+ ? createGitIgnore(ignoreList.ignoreList)
11
+ : ignoreList?.basename === '.npmignore'
12
+ ? createNPMIgnore(ignoreList.ignoreList)
13
+ : createNullIgnore();
14
+ }
15
+ function createNullIgnore() {
16
+ return { ignores: () => false, filter: (filenames) => filenames };
17
+ }
18
+ function createNPMIgnore(list) {
19
+ const mms = list.map((pattern) => new Minimatch(pattern));
20
+ const ignores = (filename) => mms.some((mm) => mm.match(filename));
21
+ return {
22
+ ignores,
23
+ filter: (filenames) => filenames.filter((filename) => !ignores(filename)),
24
+ };
25
+ }
26
+ function createGitIgnore(list) {
27
+ return gitignore().add(list);
28
+ }
29
+ async function getIgnoreList(dirname) {
30
+ for (const basename of ['.npmignore', '.gitignore']) {
31
+ const filename = path.join(dirname, basename);
32
+ try {
33
+ await access(filename, constants.F_OK);
34
+ }
35
+ catch (error) {
36
+ continue;
37
+ }
38
+ const rl = createReadlineInterface({
39
+ input: createReadStream(filename),
40
+ });
41
+ const ignoreList = [];
42
+ for await (const line of rl)
43
+ if (line.trim())
44
+ ignoreList.push(line.trim());
45
+ return {
46
+ basename,
47
+ ignoreList,
48
+ };
49
+ }
50
+ }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "esm.dev",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "TypeScript library template",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
- ".": "./src/cli.ts"
8
+ ".": "./dist/lib/index.js"
9
9
  },
10
10
  "bin": {
11
- "esm.dev": "./src/cli.ts"
11
+ "esm.dev": "./dist/cli.js"
12
12
  },
13
13
  "scripts": {
14
14
  "build": "npm run clean && tsc",
package/src/cli.ts DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env node
2
- import { runExit } from 'clipanion'
3
- import { WatchCommand } from './commands/WatchCommand.ts'
4
- import { RepublishCommand } from './commands/RepublishCommand.ts'
5
- import { LoginCommand } from './commands/LoginCommand.ts'
6
- import { TokenCommand } from './commands/TokenCommand.ts'
7
- import { WaitForRegistryCommand } from './commands/WaitForRegistryCommand.ts'
8
- import { StartCommand } from './commands/StartCommand.ts'
9
- import { InitCommand } from './commands/InitCommand.ts'
10
- import { VersionCommand } from './commands/VersionCommand.ts'
11
-
12
- runExit([
13
- InitCommand,
14
- LoginCommand,
15
- TokenCommand,
16
- RepublishCommand,
17
- StartCommand,
18
- VersionCommand,
19
- WaitForRegistryCommand,
20
- WatchCommand,
21
- ])
@@ -1,8 +0,0 @@
1
- import { Command } from 'clipanion'
2
- import { RegistrySpecific } from './mixins/RegistrySpecific.ts'
3
- import { ESMStorageSpecific } from './mixins/ESMStorageSpecific.ts'
4
- import { PackagePathSpecific } from './mixins/PackagePathSpecific.ts'
5
-
6
- export abstract class ESMDevCommand extends ESMStorageSpecific(
7
- RegistrySpecific(PackagePathSpecific(Command)),
8
- ) {}
@@ -1,71 +0,0 @@
1
- import { PackagePathSpecific } from './mixins/PackagePathSpecific.ts'
2
- import { MustacheGeneratorCommand } from './MustacheGeneratorCommand.ts'
3
- import { Option } from 'clipanion'
4
- import { isNumber } from 'typanion'
5
-
6
- export class InitCommand extends PackagePathSpecific(MustacheGeneratorCommand) {
7
- static override paths = [['init']]
8
-
9
- static override usage = this.Usage({
10
- description: 'Initialises your repo ready to work with ESM.sh locally',
11
- examples: [
12
- ['Create a minimal template', 'esm.dev init'],
13
- ["Specify the packages you're developing", 'esm.dev init packages/*'],
14
- [
15
- 'Specify different ports',
16
- 'esm.dev init --port 3001 --esm-port 8081 --registry-port 4444',
17
- ],
18
- ],
19
- })
20
-
21
- readonly esmPort = Option.String('-e,--esm-port', '8080', {
22
- description: 'The port of the ESM Server',
23
- validator: isNumber(),
24
- })
25
-
26
- readonly esmStoragePath = Option.String(
27
- '-s,--esm-storage-path',
28
- './docker-storage/esm',
29
- {
30
- description: "Path to ESM.sh's storage",
31
- },
32
- )
33
-
34
- readonly port = Option.String('-p,--port', '3000', {
35
- description: "The server's port",
36
- })
37
-
38
- readonly outputDirectory = Option.String('-o,--output-dir', '.', {
39
- description: 'The output directory',
40
- })
41
-
42
- readonly registryPort = Option.String('-r,--registry-port', '4873', {
43
- description: 'The port of your local registry',
44
- validator: isNumber(),
45
- })
46
-
47
- esmURL!: URL
48
- npmRegistryURL!: URL
49
- packages!: { path: string; basename: string }[]
50
-
51
- override async execute() {
52
- const path = await import('node:path')
53
- this.templateDir = path.resolve(
54
- import.meta.dirname,
55
- '..',
56
- '..',
57
- 'templates',
58
- 'init',
59
- )
60
- this.destinationDir = this.outputDirectory
61
- this.packages = this.packagePaths.map((packagePath) => ({
62
- path: packagePath,
63
- basename: path.basename(packagePath),
64
- }))
65
- await this.removeDestinationFile(
66
- 'docker-compose.yaml',
67
- 'docker-compose.yml.mustache',
68
- )
69
- await super.execute()
70
- }
71
- }
@@ -1,15 +0,0 @@
1
- import { Command } from 'clipanion'
2
- import { RegistrySpecific } from './mixins/RegistrySpecific.ts'
3
-
4
- export class LoginCommand extends RegistrySpecific(Command) {
5
- static override paths = [['login']]
6
-
7
- static override usage = this.Usage({
8
- description: 'Login in to the NPM registry',
9
- })
10
-
11
- override async execute() {
12
- const { login } = await import('../lib/login.ts')
13
- return login(this.registry)
14
- }
15
- }
@@ -1,10 +0,0 @@
1
- import { GeneratorCommand } from 'clipanion-generator-command'
2
- import { MustacheGenerator } from '../lib/MustacheGenerator.ts'
3
-
4
- export abstract class MustacheGeneratorCommand extends GeneratorCommand {
5
- override get generator() {
6
- return new MustacheGenerator(this.templateDir, this.destinationDir, [
7
- '.mustache',
8
- ])
9
- }
10
- }
@@ -1,15 +0,0 @@
1
- import { ESMDevCommand } from './ESMDevCommand.ts'
2
-
3
- export class RepublishCommand extends ESMDevCommand {
4
- static override paths = [['republish']]
5
-
6
- static override usage = this.Usage({
7
- description:
8
- 'Removes the references, of given packages, from the ESM server and registry and republishes.',
9
- })
10
-
11
- override async execute() {
12
- const { republish } = await import('../lib/republish.ts')
13
- await this.eachPackagePath((packagePath) => republish(packagePath, this))
14
- }
15
- }
@@ -1,23 +0,0 @@
1
- import { ESMDevCommand } from './ESMDevCommand.ts'
2
- import { Servable } from './mixins/Servable.ts'
3
- import { Watchable } from './mixins/Watchable.ts'
4
- import { ESMServed } from './mixins/ESMServed.ts'
5
-
6
- export class StartCommand extends Servable(
7
- Watchable(ESMServed(ESMDevCommand)),
8
- ) {
9
- static override paths = [['start']]
10
-
11
- static override usage = this.Usage({
12
- description: 'Runs a server and concurrently watches a file system',
13
- })
14
-
15
- override async execute() {
16
- const [{ watch }, { serve }] = await Promise.all([
17
- import('../lib/watch.ts'),
18
- import('../lib/server.ts'),
19
- ])
20
- serve(this.port, this.esmOrigin)
21
- await this.eachPackagePath((packagePath) => watch(packagePath, this))
22
- }
23
- }
@@ -1,29 +0,0 @@
1
- import { Command } from 'clipanion'
2
- import { RegistrySpecific } from './mixins/RegistrySpecific.ts'
3
-
4
- export class TokenCommand extends RegistrySpecific(Command) {
5
- static override paths = [['token']]
6
-
7
- static override usage = this.Usage({
8
- description: 'Get the NPM token',
9
- })
10
-
11
- override async execute() {
12
- const [{ default: escapeStringRegexp }, { readFile }] = await Promise.all([
13
- import('escape-string-regexp'),
14
- import('node:fs/promises'),
15
- ])
16
- const npmrc = await readFile('~/.npmrc', 'utf-8')
17
- const url = new URL(this.registry)
18
- const regex = new RegExp(
19
- `^//${escapeStringRegexp(url.hostname)}/:_authToken=(.*)$`,
20
- 'm',
21
- )
22
- const match = regex.exec(npmrc)
23
- if (!match) {
24
- this.context.stderr.write(`Token has not been created yet\n`)
25
- return 1
26
- }
27
- this.context.stdout.write(match[1] + '\n')
28
- }
29
- }
@@ -1,23 +0,0 @@
1
- import { Command } from 'clipanion'
2
-
3
- export class VersionCommand extends Command {
4
- static override paths = [['version']]
5
-
6
- static override usage = this.Usage({
7
- description: 'Display the version of esm.dev',
8
- })
9
-
10
- override async execute(): Promise<number | void> {
11
- const [path, { readFile }] = await Promise.all([
12
- import('node:path'),
13
- import('node:fs/promises'),
14
- ])
15
- const pckg = JSON.parse(
16
- await readFile(
17
- path.resolve(import.meta.dirname, '..', '..', 'package.json'),
18
- 'utf-8',
19
- ),
20
- )
21
- this.context.stdout.write(`${pckg.version}\n`)
22
- }
23
- }
@@ -1,17 +0,0 @@
1
- import { Command } from 'clipanion'
2
- import { RegistrySpecific } from './mixins/RegistrySpecific.ts'
3
- import { Retryable } from './mixins/Retryable.ts'
4
-
5
- export class WaitForRegistryCommand extends Retryable(
6
- RegistrySpecific(Command),
7
- ) {
8
- static override paths = [['wait-for-registry'], ['wfr']]
9
-
10
- static override usage = this.Usage({
11
- description: 'wait for the registry to be online',
12
- })
13
-
14
- override async execute() {
15
- return this.retry(this.registry)
16
- }
17
- }
@@ -1,15 +0,0 @@
1
- import { ESMDevCommand } from './ESMDevCommand.ts'
2
- import { Watchable } from './mixins/Watchable.ts'
3
-
4
- export class WatchCommand extends Watchable(ESMDevCommand) {
5
- static override paths = [['watch']]
6
-
7
- static override usage = this.Usage({
8
- description: 'Watches directories and republishes on changes',
9
- })
10
-
11
- override async execute() {
12
- const { watch } = await import('../lib/watch.ts')
13
- await this.eachPackagePath((packagePath) => watch(packagePath, this))
14
- }
15
- }
@@ -1,3 +0,0 @@
1
- import type { Command } from 'clipanion'
2
-
3
- export type CommandClass = abstract new (...args: any[]) => Command
@@ -1,12 +0,0 @@
1
- import { EnvOption } from '../options/EnvOption.ts'
2
- import type { CommandClass } from './CommandClass.ts'
3
-
4
- export function ESMServed<T extends CommandClass>(Base: T) {
5
- abstract class ESMServed extends Base {
6
- readonly esmOrigin = EnvOption('ESM_ORIGIN', '-e,--esm-origin', {
7
- description: 'The base URL of the ESM Server',
8
- })
9
- }
10
-
11
- return ESMServed
12
- }
@@ -1,16 +0,0 @@
1
- import type { CommandClass } from './CommandClass.ts'
2
- import { EnvOption } from '../options/EnvOption.ts'
3
-
4
- export function ESMStorageSpecific<T extends CommandClass>(Base: T) {
5
- abstract class ESMStorageSpecific extends Base {
6
- readonly esmStoragePath = EnvOption(
7
- 'ESM_STORAGE_PATH',
8
- '-s,--esm-storage-path',
9
- {
10
- description: "Path to ESM.sh's storage",
11
- },
12
- )
13
- }
14
-
15
- return ESMStorageSpecific
16
- }
@@ -1,18 +0,0 @@
1
- import { Option } from 'clipanion'
2
- import type { CommandClass } from './CommandClass.ts'
3
-
4
- export function PackagePathSpecific<T extends CommandClass>(Base: T) {
5
- abstract class PackagePathSpecific extends Base {
6
- readonly packagePaths = Option.Rest({
7
- name: 'packages',
8
- })
9
-
10
- protected async eachPackagePath(cb: (packagePath: string) => Promise<any>) {
11
- const { glob } = await import('glob')
12
- const packagePaths = await glob(this.packagePaths)
13
- await Promise.all(packagePaths.map(cb))
14
- }
15
- }
16
-
17
- return PackagePathSpecific
18
- }
@@ -1,12 +0,0 @@
1
- import type { CommandClass } from './CommandClass.ts'
2
- import { EnvOption } from '../options/EnvOption.ts'
3
-
4
- export function RegistrySpecific<TBase extends CommandClass>(Base: TBase) {
5
- abstract class RegistrySpecific extends Base {
6
- readonly registry = EnvOption('NPM_REGISTRY', '-r,--registry', {
7
- description: 'The URL of your local registry',
8
- })
9
- }
10
-
11
- return RegistrySpecific
12
- }
@@ -1,33 +0,0 @@
1
- import { Option } from 'clipanion'
2
- import { isNumber } from 'typanion'
3
- import type { CommandClass } from './CommandClass.ts'
4
-
5
- export function Retryable<T extends CommandClass>(Base: T) {
6
- abstract class Retryable extends Base {
7
- readonly timeout = Option.String('-t,--timeout', '10000', {
8
- description: 'The amount of total ms to keep trying for',
9
- validator: isNumber(),
10
- })
11
-
12
- readonly interval = Option.String('-i,--interval', '300', {
13
- description: 'The amount of ms inbetween each attempt',
14
- validator: isNumber(),
15
- })
16
-
17
- protected async retry(endpoint: string) {
18
- const { EndpointUnavailableError, waitForEndpoint } = await import(
19
- '../../lib/until.ts'
20
- )
21
- try {
22
- await waitForEndpoint({ ...this, endpoint })
23
- } catch (error) {
24
- if (error instanceof EndpointUnavailableError) {
25
- this.context.stderr.write(`${endpoint} is not available\n`)
26
- return 1
27
- } else throw error
28
- }
29
- }
30
- }
31
-
32
- return Retryable
33
- }
@@ -1,14 +0,0 @@
1
- import { isNumber } from 'typanion'
2
- import { EnvOption } from '../options/EnvOption.ts'
3
- import type { CommandClass } from './CommandClass.ts'
4
-
5
- export function Servable<T extends CommandClass>(Base: T) {
6
- abstract class Servable extends Base {
7
- readonly port = EnvOption('PORT', '-p,--port', {
8
- description: 'The port to run the server on',
9
- validator: isNumber(),
10
- })
11
- }
12
-
13
- return Servable
14
- }
@@ -1,13 +0,0 @@
1
- import { Option } from 'clipanion'
2
- import type { CommandClass } from './CommandClass.ts'
3
-
4
- export function Watchable<T extends CommandClass>(Base: T) {
5
- abstract class Watchable extends Base {
6
- readonly legacyMethod = Option.Boolean('-l,--legacy-method', false, {
7
- description:
8
- 'Use a less performant, legacy, watch method. Sometimes needed in docker or vagrant environments.',
9
- })
10
- }
11
-
12
- return Watchable
13
- }
@@ -1,27 +0,0 @@
1
- import { Option } from 'clipanion'
2
- import type { StrictValidator } from 'typanion'
3
-
4
- /**
5
- * @see https://github.com/arcanis/clipanion/issues/174
6
- */
7
- export function EnvOption<T extends {}>(
8
- envName: string,
9
- descriptor: string,
10
- opts: { description?: string; validator: StrictValidator<unknown, T> },
11
- ): T
12
-
13
- export function EnvOption(
14
- envName: string,
15
- descriptor: string,
16
- opts?: { description?: string },
17
- ): string
18
-
19
- export function EnvOption<T extends {}>(
20
- envName: string,
21
- descriptor: string,
22
- opts: { description?: string; validator?: StrictValidator<unknown, T> } = {},
23
- ) {
24
- return process.env[envName]
25
- ? Option.String(descriptor, process.env[envName], opts)
26
- : Option.String(descriptor, { ...opts, required: true })
27
- }
@@ -1,10 +0,0 @@
1
- import Mustache from 'mustache'
2
- import { Generator } from 'clipanion-generator-command/Generator'
3
-
4
- export class MustacheGenerator extends Generator {
5
- override renderTemplate(templateContext: any, template: string): string {
6
- return Mustache.render(template, templateContext, undefined, {
7
- escape: (x) => x,
8
- })
9
- }
10
- }
@@ -1,15 +0,0 @@
1
- import { readFile, stat as getStat } from 'node:fs/promises'
2
- import * as path from 'node:path'
3
-
4
- export async function getPackageMeta(
5
- packagePath: string,
6
- ): Promise<{ name: string; packageRoot: string; private?: boolean }> {
7
- const stat = await getStat(packagePath)
8
- const packageRoot = stat.isDirectory()
9
- ? packagePath
10
- : path.dirname(packagePath)
11
- const pckg = JSON.parse(
12
- await readFile(path.join(packageRoot, 'package.json'), 'utf-8'),
13
- )
14
- return { name: pckg.name, packageRoot, private: pckg.private }
15
- }
package/src/lib/login.ts DELETED
@@ -1,29 +0,0 @@
1
- import { spawn } from 'node:child_process'
2
-
3
- export function login(registry: string): Promise<number> {
4
- return new Promise((resolve) => {
5
- const child = spawn('npm', ['login', '--registry', registry, '--quiet'])
6
-
7
- child.stderr.on('data', (d) => console.error(d.toString()))
8
-
9
- child.stdout.on('data', (d) => {
10
- const data = d.toString()
11
- switch (true) {
12
- case /username/i.test(data):
13
- child.stdin.write('esm.dev\n')
14
- break
15
- case /password/i.test(data):
16
- child.stdin.write('esm.dev\n')
17
- break
18
- case /email/i.test(data):
19
- child.stdin.write('esm.dev@esm.dev.com')
20
- break
21
- case /logged in as/i.test(data):
22
- child.stdin.end()
23
- break
24
- }
25
- })
26
-
27
- child.on('exit', resolve)
28
- })
29
- }
@@ -1,14 +0,0 @@
1
- import { $ } from 'zx'
2
- import * as path from 'node:path'
3
-
4
- export async function publish({
5
- packageRoot,
6
- registry,
7
- }: {
8
- packageRoot: string
9
- registry: string
10
- }): Promise<void> {
11
- await $({
12
- cwd: path.resolve(packageRoot),
13
- })`npm publish --registry ${registry}`
14
- }
package/src/lib/queue.ts DELETED
@@ -1,65 +0,0 @@
1
- import { debounce, Mutex } from 'es-toolkit'
2
-
3
- const mutex = new Mutex()
4
-
5
- export async function queue<TResult>(
6
- fn: () => Promise<TResult>,
7
- signal?: AbortSignal,
8
- ): Promise<TResult> {
9
- await mutex.acquire()
10
- try {
11
- signal?.throwIfAborted()
12
- return await fn()
13
- } finally {
14
- mutex.release()
15
- }
16
- }
17
-
18
- /**
19
- * Just like debounce, but the first call will add a promise to the queue
20
- * and that promise won't resolve until the debounced function is finally called.
21
- */
22
- export function queuedDebounce<Args extends unknown[], R>(
23
- fn: (...args: Args) => R,
24
- delay: number,
25
- signal?: AbortSignal,
26
- ): (...args: Args) => Promise<Awaited<R>> {
27
- let promiseWithResolvers: PromiseWithResolvers<R> | undefined
28
- let queuedPromise: Promise<Awaited<R>> | undefined
29
-
30
- signal?.addEventListener('abort', (reason) => {
31
- debounced.cancel()
32
- promiseWithResolvers?.reject(reason)
33
- })
34
-
35
- const debounced = debounce(
36
- async (...args: Args) => {
37
- try {
38
- const result = await fn(...args)
39
- promiseWithResolvers?.resolve(result)
40
- } catch (error: any) {
41
- promiseWithResolvers?.reject(error)
42
- } finally {
43
- promiseWithResolvers = undefined
44
- }
45
- },
46
- delay,
47
- { signal },
48
- )
49
-
50
- return (...args: Args) => {
51
- const promise = start()
52
- debounced(...args)
53
- return promise as Promise<Awaited<R>>
54
- }
55
-
56
- function start() {
57
- if (!queuedPromise) {
58
- promiseWithResolvers = Promise.withResolvers<R>()
59
- queuedPromise = queue(
60
- async () => promiseWithResolvers?.promise,
61
- ) as Promise<Awaited<R>>
62
- }
63
- return queuedPromise
64
- }
65
- }
@@ -1,16 +0,0 @@
1
- import { getPackageMeta } from './getPackageMeta.ts'
2
- import { publish } from './publish.ts'
3
- import { unpublish } from './unpublish.ts'
4
-
5
- export async function republish(
6
- packagePath: string,
7
- opts: {
8
- registry: string
9
- esmStoragePath: string
10
- },
11
- ): Promise<void> {
12
- console.info(`Republishing ${packagePath}`)
13
- const { name, packageRoot } = await getPackageMeta(packagePath)
14
- await unpublish({ ...opts, name })
15
- await publish({ ...opts, packageRoot })
16
- }