@vanillaes/esmtk 0.8.0 → 0.10.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.
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "version": "0.2.0",
3
3
  "configurations": [
4
+ {
5
+ "name": "Version",
6
+ "type": "node",
7
+ "request": "launch",
8
+ "skipFiles": [
9
+ "<node_internals>/**"
10
+ ],
11
+ "program": "${workspaceFolder}/bin/esmtk.js",
12
+ "cwd": "${workspaceFolder}",
13
+ "args": ["--version"],
14
+ "console": "integratedTerminal",
15
+ },
4
16
  {
5
17
  "name": "Lint",
6
18
  "type": "node",
@@ -22,7 +34,19 @@
22
34
  ],
23
35
  "program": "${workspaceFolder}/bin/esmtk.js",
24
36
  "cwd": "${workspaceFolder}",
25
- "args": ["types", "./test/index.js"],
37
+ "args": ["types", "./src/index.js"],
38
+ "console": "integratedTerminal",
39
+ },
40
+ {
41
+ "name": "Typings",
42
+ "type": "node",
43
+ "request": "launch",
44
+ "skipFiles": [
45
+ "<node_internals>/**"
46
+ ],
47
+ "program": "${workspaceFolder}/bin/esmtk.js",
48
+ "cwd": "${workspaceFolder}",
49
+ "args": ["typings", "./src/index.js"],
26
50
  "console": "integratedTerminal",
27
51
  },
28
52
  {
package/README.md CHANGED
@@ -34,6 +34,7 @@ Type check the JSDoc typings (using Typescript)
34
34
  `esmtk types index.js`
35
35
 
36
36
  - `[entry]` - the entry-point for the source
37
+ - `--strict` - enable 'strict mode' type checks
37
38
 
38
39
  ### Usage
39
40
 
@@ -41,6 +42,22 @@ Type check the JSDoc typings (using Typescript)
41
42
  esmtk types index.js
42
43
  ```
43
44
 
45
+ ## Typings
46
+
47
+ Generate Type Declarations (.d.ts) from JSDoc (using Typescript)
48
+
49
+ ### Arguments
50
+
51
+ `esmtk typings index.js`
52
+
53
+ - `[entry]` - the entry-point for the source
54
+
55
+ ### Usage
56
+
57
+ ```sh
58
+ esmtk typings index.js
59
+ ```
60
+
44
61
  ## Bundle
45
62
 
46
63
  Bundle the source code to an ECMAScript module (using ESBuild)
@@ -1,4 +1,4 @@
1
- import { installed, which } from '../../src/util.js'
1
+ import { installed, which } from '../../src/index.js'
2
2
  import { spawn } from 'child_process'
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { installed, which } from '../../src/util.js'
1
+ import { installed, which } from '../../src/index.js'
2
2
  import { spawn } from 'child_process'
3
3
 
4
4
  /**
@@ -5,3 +5,4 @@ export { lint } from './lint.js'
5
5
  export { minify } from './minify.js'
6
6
  export { rm } from './rm.js'
7
7
  export { types } from './types.js'
8
+ export { typings } from './typings.js'
@@ -1,4 +1,4 @@
1
- import { installed, which } from '../../src/util.js'
1
+ import { installed, which } from '../../src/index.js'
2
2
  import { spawn } from 'child_process'
3
3
 
4
4
  /**
@@ -1,11 +1,11 @@
1
- import { installed, which } from '../../src/util.js'
1
+ import { installed, which } from '../../src/index.js'
2
2
  import { spawn } from 'child_process'
3
3
 
4
4
  /**
5
5
  * Type Check the JSDOC typings
6
6
  * @param {string} entry the entry point
7
7
  */
8
- export async function types (entry) {
8
+ export async function types (entry, options) {
9
9
  const npmExists = await which('npm')
10
10
  if (!npmExists) {
11
11
  console.error('npm not found')
@@ -20,10 +20,19 @@ export async function types (entry) {
20
20
  process.exit(1)
21
21
  }
22
22
 
23
- spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--noEmit'], {
24
- cwd: process.cwd(),
25
- stdio: ['pipe', process.stdout, process.stderr]
26
- }).on('error', err => {
27
- console.error(err)
28
- })
23
+ if (options?.strict) {
24
+ spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--noEmit', '--strict'], {
25
+ cwd: process.cwd(),
26
+ stdio: ['pipe', process.stdout, process.stderr]
27
+ }).on('error', err => {
28
+ console.error(err)
29
+ })
30
+ } else {
31
+ spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--noEmit'], {
32
+ cwd: process.cwd(),
33
+ stdio: ['pipe', process.stdout, process.stderr]
34
+ }).on('error', err => {
35
+ console.error(err)
36
+ })
37
+ }
29
38
  }
@@ -0,0 +1,29 @@
1
+ import { installed, which } from '../../src/index.js'
2
+ import { spawn } from 'child_process'
3
+
4
+ /**
5
+ * Generate Typescript typings from JSDoc
6
+ * @param {string} entry the entry point
7
+ */
8
+ export async function typings (entry) {
9
+ const npmExists = await which('npm')
10
+ if (!npmExists) {
11
+ console.error('npm not found')
12
+ console.error('is node installed?')
13
+ process.exit(1)
14
+ }
15
+
16
+ const esbuildExists = await installed('typescript')
17
+ if (!esbuildExists) {
18
+ console.error('typescript not found')
19
+ console.error('typescript can be installed with `npm i -g typescript`')
20
+ process.exit(1)
21
+ }
22
+
23
+ spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--declaration', '--emitDeclarationOnly', '--noEmitOnError'], {
24
+ cwd: process.cwd(),
25
+ stdio: ['pipe', process.stdout, process.stderr]
26
+ }).on('error', err => {
27
+ console.error(err)
28
+ })
29
+ }
package/bin/esmtk.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { bundle, cp, commonjs, lint, minify, rm, types } from './commands/index.js'
2
+ import { bundle, cp, commonjs, lint, minify, rm, types, typings } from './commands/index.js'
3
3
  import { Command } from 'commander'
4
4
  import { createRequire } from 'module'
5
5
  const program = new Command()
@@ -18,8 +18,15 @@ program.command('lint')
18
18
 
19
19
  program.command('types <entry>')
20
20
  .description('Type check the JSDoc typings using Typescript')
21
+ .option('--strict', 'Enable strict type checks')
22
+ .action((entry, options) => {
23
+ types(entry, options)
24
+ })
25
+
26
+ program.command('typings <entry>')
27
+ .description('Generate typings from JSDoc using Typescript')
21
28
  .action((entry) => {
22
- types(entry)
29
+ typings(entry)
23
30
  })
24
31
 
25
32
  program.command('bundle <input> <output>')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "esm",
@@ -13,17 +13,27 @@
13
13
  "author": "Evan Plaice <evanplaice@gmail.com> (https://evanplaice.com/)",
14
14
  "license": "MIT",
15
15
  "type": "module",
16
- "exports": {
17
- ".": "./src/index.js",
18
- "./cp": "./src/cp.js",
19
- "./rm": "./src/rm.js"
20
- },
21
16
  "bin": {
22
17
  "esmtk": "bin/esmtk.js"
23
18
  },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./src/index.d.ts",
22
+ "default": "./src/index.js"
23
+ },
24
+ "./cp": {
25
+ "types": "./src/cp.d.ts",
26
+ "default": "./src/cp.js"
27
+ },
28
+ "./rm": {
29
+ "types": "./src/rm.d.ts",
30
+ "default": "./src/rm.js"
31
+ }
32
+ },
24
33
  "scripts": {
25
34
  "lint": "./bin/esmtk.js lint",
26
35
  "types": "./bin/esmtk.js types src/index.js",
36
+ "typings": "./bin/esmtk.js typings src/index.js",
27
37
  "preversion": "npm run lint && npm run types",
28
38
  "postversion": "git push --follow-tags"
29
39
  },
@@ -31,9 +41,6 @@
31
41
  "commander": "^14.0.3",
32
42
  "standard": "^17.1.2"
33
43
  },
34
- "engines": {
35
- "node": ">=17"
36
- },
37
44
  "devDependencies": {
38
45
  "@types/node": "^25.3.5"
39
46
  }
package/src/cp.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copy a single file asynchronously
3
+ * @param {string} source The source file
4
+ * @param {string} target The target file
5
+ * @param {boolean} force If the file already exists, overwrite it (default false)
6
+ */
7
+ export function copyAsync(source: string, target: string, force?: boolean): Promise<void>;
8
+ /**
9
+ * Recursively copy a directory asynchronously
10
+ * @param {string} source The source directory
11
+ * @param {string} target The target directory
12
+ * @param {boolean} force If the file already exists, overwrite it (default false)
13
+ */
14
+ export function copyRecursiveAsync(source: string, target: string, force?: boolean): Promise<void>;
package/src/cp.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { fileExists } from './index.js'
1
2
  import { basename, dirname } from 'node:path'
2
- import { access, constants, cp, stat } from 'node:fs/promises'
3
+ import { cp, stat } from 'node:fs/promises'
3
4
 
4
5
  /**
5
6
  * Copy a single file asynchronously
@@ -86,12 +87,3 @@ export async function copyRecursiveAsync (source, target, force = false) {
86
87
  console.error(`cp": error ${err.message}`)
87
88
  }
88
89
  }
89
-
90
- async function fileExists (file) {
91
- try {
92
- await access(file, constants.F_OK)
93
- return true
94
- } catch (error) {
95
- return false
96
- }
97
- }
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { copyAsync, copyRecursiveAsync } from "./cp.js";
2
+ export { removeAsync, removeRecursiveAsync } from "./rm.js";
3
+ export { fileExists, installed, which } from "./util.js";
package/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { copyAsync, copyRecursiveAsync } from './cp.js'
2
2
  export { removeAsync, removeRecursiveAsync } from './rm.js'
3
+ export { fileExists, installed, which } from './util.js'
package/src/rm.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Remove a file asynchronously
3
+ * @param {string} path The file to delete
4
+ * @param {boolean} force Ignore exceptions if the file doesn't exist (default false)
5
+ */
6
+ export function removeAsync(path: string, force?: boolean): Promise<void>;
7
+ /**
8
+ * Recursively remove a file|directory asynchronously
9
+ * @param {string} path The file|directory to remove
10
+ * @param {boolean} force Ignore exceptions if the file|directory doesn't exist (default false)
11
+ */
12
+ export function removeRecursiveAsync(path: string, force?: boolean): Promise<void>;
package/src/rm.js CHANGED
@@ -1,4 +1,5 @@
1
- import { access, constants, rm, stat } from 'node:fs/promises'
1
+ import { fileExists } from './index.js'
2
+ import { rm, stat } from 'node:fs/promises'
2
3
 
3
4
  /**
4
5
  * Remove a file asynchronously
@@ -47,12 +48,3 @@ export async function removeRecursiveAsync (path, force = false) {
47
48
  console.error(`rm": error ${err.message}`)
48
49
  }
49
50
  }
50
-
51
- async function fileExists (file) {
52
- try {
53
- await access(file, constants.F_OK)
54
- return true
55
- } catch (error) {
56
- return false
57
- }
58
- }
package/src/util.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Check if a file/folder exists
3
+ * @param {string} path the path to the file/folder
4
+ * @returns {Promise<boolean>} trie if the file/folder exists, false otherwise
5
+ */
6
+ export function fileExists(path: string): Promise<boolean>;
7
+ /**
8
+ * Check to see if a NPM package is installed globally
9
+ * @param {string} pkg the name of the package
10
+ * @returns {Promise<boolean>} true if the package is installed, false otherwise
11
+ */
12
+ export function installed(pkg: string): Promise<boolean>;
13
+ /**
14
+ * Check to see if an application is installed globally
15
+ * @param {string} program the name of the application
16
+ * @returns {Promise<boolean>} true if the application is installed, false otherwise
17
+ */
18
+ export function which(program: string): Promise<boolean>;
package/src/util.js CHANGED
@@ -1,12 +1,27 @@
1
1
  import { exec } from 'child_process'
2
+ import { access, constants } from 'node:fs/promises'
2
3
  import { promisify } from 'node:util'
3
4
 
4
5
  const execAsync = promisify(exec)
5
6
 
7
+ /**
8
+ * Check if a file/folder exists
9
+ * @param {string} path the path to the file/folder
10
+ * @returns {Promise<boolean>} trie if the file/folder exists, false otherwise
11
+ */
12
+ export async function fileExists (path) {
13
+ try {
14
+ await access(path, constants.F_OK)
15
+ return true
16
+ } catch (error) {
17
+ return false
18
+ }
19
+ }
20
+
6
21
  /**
7
22
  * Check to see if a NPM package is installed globally
8
23
  * @param {string} pkg the name of the package
9
- * @returns {boolean} true if the package is installed, false otherwise
24
+ * @returns {Promise<boolean>} true if the package is installed, false otherwise
10
25
  */
11
26
  export async function installed (pkg) {
12
27
  try {
@@ -20,7 +35,7 @@ export async function installed (pkg) {
20
35
  /**
21
36
  * Check to see if an application is installed globally
22
37
  * @param {string} program the name of the application
23
- * @returns {boolean} true if the application is installed, false otherwise
38
+ * @returns {Promise<boolean>} true if the application is installed, false otherwise
24
39
  */
25
40
  export async function which (program) {
26
41
  try {