@plugjs/plug 0.0.10 → 0.0.11
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/package.json +1 -1
- package/src/files.ts +2 -2
- package/src/fork.ts +2 -2
- package/src/helpers.ts +19 -2
- package/src/paths.ts +3 -3
- package/src/plugs/esbuild/fix-extensions.ts +3 -3
- package/src/plugs/eslint/runner.ts +3 -3
- package/src/plugs/exec.ts +4 -4
- package/src/plugs/tsc/runner.ts +3 -3
package/package.json
CHANGED
package/src/files.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from './assert.js'
|
|
2
|
-
import { AbsolutePath, assertRelativeChildPath, getAbsoluteParent,
|
|
2
|
+
import { AbsolutePath, assertRelativeChildPath, getAbsoluteParent, resolveFile, resolveAbsolutePath } from './paths.js'
|
|
3
3
|
import { mkdir, writeFile } from './utils/asyncfs.js'
|
|
4
4
|
|
|
5
5
|
/** The {@link FilesBuilder} interface defines a builder for {@link Files}. */
|
|
@@ -102,7 +102,7 @@ export class Files {
|
|
|
102
102
|
const relative = assertRelativeChildPath(instance.directory, file)
|
|
103
103
|
const resolved = resolveAbsolutePath(instance.directory, file)
|
|
104
104
|
|
|
105
|
-
assert(
|
|
105
|
+
assert(resolveFile(resolved), `File "${resolved}" does not exist`)
|
|
106
106
|
set.add(relative)
|
|
107
107
|
}
|
|
108
108
|
|
package/src/fork.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { assert, failure } from './assert.js'
|
|
|
3
3
|
import { runAsync } from './async.js'
|
|
4
4
|
import { Files } from './files.js'
|
|
5
5
|
import { $gry, $p, LogOptions, logOptions } from './log.js'
|
|
6
|
-
import { AbsolutePath,
|
|
6
|
+
import { AbsolutePath, resolveFile, requireFilename } from './paths.js'
|
|
7
7
|
import { install, Plug, PlugName } from './pipe.js'
|
|
8
8
|
import { Run, RunImpl } from './run.js'
|
|
9
9
|
|
|
@@ -220,7 +220,7 @@ if ((process.argv[1] === requireFilename(__fileurl)) && (process.send)) {
|
|
|
220
220
|
/* Contextualize this run, and go! */
|
|
221
221
|
const result = runAsync(run, taskName, async () => {
|
|
222
222
|
/* Check that we have a proper script file name */
|
|
223
|
-
assert(
|
|
223
|
+
assert(resolveFile(scriptFile), `Script file ${$p(scriptFile)} not found`)
|
|
224
224
|
const script = await import(scriptFile)
|
|
225
225
|
|
|
226
226
|
/* Figure out the constructor, in the "default" chain */
|
package/src/helpers.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbsolutePath,
|
|
3
|
+
commonPath,
|
|
4
|
+
getCurrentWorkingDirectory,
|
|
5
|
+
resolveDirectory,
|
|
6
|
+
resolveFile,
|
|
7
|
+
} from './paths.js'
|
|
8
|
+
|
|
1
9
|
import { assert } from './assert.js'
|
|
2
10
|
import { currentRun } from './async.js'
|
|
3
11
|
import { Files, FilesBuilder } from './files.js'
|
|
4
12
|
import { $p, log, LogLevelString } from './log.js'
|
|
5
|
-
import { AbsolutePath, commonPath, getCurrentWorkingDirectory, isDirectory } from './paths.js'
|
|
6
13
|
import { Pipe } from './pipe.js'
|
|
7
14
|
import { FindOptions } from './run.js'
|
|
8
15
|
import { rm } from './utils/asyncfs.js'
|
|
@@ -22,7 +29,7 @@ export async function rmrf(directory: string): Promise<void> {
|
|
|
22
29
|
assert(dir !== run.buildDir,
|
|
23
30
|
`Cowardly refusing to wipe build file directory ${$p(dir)}`)
|
|
24
31
|
|
|
25
|
-
if (!
|
|
32
|
+
if (! resolveDirectory(dir)) {
|
|
26
33
|
log.info('Directory', $p(dir), 'not found')
|
|
27
34
|
return
|
|
28
35
|
}
|
|
@@ -114,3 +121,13 @@ export function pipe(files: Files | Promise<Files>): Pipe & Promise<Files> {
|
|
|
114
121
|
assert(run, 'Unable to create pipes outside a running task')
|
|
115
122
|
return run.pipe(files)
|
|
116
123
|
}
|
|
124
|
+
|
|
125
|
+
/** Return an absolute path of the file if it exist on disk */
|
|
126
|
+
export function isFile(...paths: string[]): AbsolutePath | undefined {
|
|
127
|
+
return resolveFile(resolve(...paths))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Return an absolute path of the file if it exist on disk */
|
|
131
|
+
export function isDirectory(...paths: string[]): AbsolutePath | undefined {
|
|
132
|
+
return resolveDirectory(resolve(...paths))
|
|
133
|
+
}
|
package/src/paths.ts
CHANGED
|
@@ -133,7 +133,7 @@ export function requireResolve(__fileurl: string, module: string): AbsolutePath
|
|
|
133
133
|
|
|
134
134
|
for (const check of checks) {
|
|
135
135
|
const resolved = fileURLToPath(new URL(check, url)) as AbsolutePath
|
|
136
|
-
if (
|
|
136
|
+
if (resolveFile(resolved)) {
|
|
137
137
|
module = check
|
|
138
138
|
break
|
|
139
139
|
}
|
|
@@ -187,7 +187,7 @@ export function commonPath(path: AbsolutePath, ...paths: string[]): AbsolutePath
|
|
|
187
187
|
* Resolves the specified path as an {@link AbsolutePath} and checks it is a
|
|
188
188
|
* _file_, returning `undefined` if it is not.
|
|
189
189
|
*/
|
|
190
|
-
export function
|
|
190
|
+
export function resolveFile(path: AbsolutePath, ...paths: string[]): AbsolutePath | undefined {
|
|
191
191
|
const file = resolveAbsolutePath(path, ...paths)
|
|
192
192
|
try {
|
|
193
193
|
const stat = statSync(file)
|
|
@@ -202,7 +202,7 @@ export function isFile(path: AbsolutePath, ...paths: string[]): AbsolutePath | u
|
|
|
202
202
|
* Resolves the specified path as an {@link AbsolutePath} and checks it is a
|
|
203
203
|
* _directory_, returning `undefined` if it is not.
|
|
204
204
|
*/
|
|
205
|
-
export function
|
|
205
|
+
export function resolveDirectory(path: AbsolutePath, ...paths: string[]): AbsolutePath | undefined {
|
|
206
206
|
const directory = resolveAbsolutePath(path, ...paths)
|
|
207
207
|
try {
|
|
208
208
|
const stat = statSync(directory)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { Plugin } from 'esbuild'
|
|
4
|
-
import { assertAbsolutePath,
|
|
4
|
+
import { assertAbsolutePath, resolveFile, resolveAbsolutePath } from '../../paths.js'
|
|
5
5
|
import { stat } from '../../utils/asyncfs.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -61,7 +61,7 @@ export function fixExtensions(): Plugin {
|
|
|
61
61
|
|
|
62
62
|
/* First of all, check if the _real_ filename exists */
|
|
63
63
|
const resolved = resolveAbsolutePath(resolveDir, args.path)
|
|
64
|
-
if (
|
|
64
|
+
if (resolveFile(resolved)) return { path: args.path, external: true }
|
|
65
65
|
|
|
66
66
|
/*
|
|
67
67
|
* Thank you TypeScript 4.7!!! If the file is ".js", ".mjs" or ".cjs" we
|
|
@@ -73,7 +73,7 @@ export function fixExtensions(): Plugin {
|
|
|
73
73
|
const [ , name, ext ] = match
|
|
74
74
|
const tspath = name + ext.replace('js', 'ts')
|
|
75
75
|
const tsfile = resolveAbsolutePath(resolveDir, tspath)
|
|
76
|
-
if (
|
|
76
|
+
if (resolveFile(tsfile)) {
|
|
77
77
|
const newext = ext === '.mjs' ? mjs : ext === '.cjs' ? cjs : js
|
|
78
78
|
return { path: name + newext, external: true }
|
|
79
79
|
}
|
|
@@ -2,7 +2,7 @@ import { ESLint as RealESLint } from 'eslint'
|
|
|
2
2
|
import { assert, failure } from '../../assert.js'
|
|
3
3
|
import { Files } from '../../files.js'
|
|
4
4
|
import { $p, ERROR, NOTICE, WARN } from '../../log.js'
|
|
5
|
-
import { getCurrentWorkingDirectory,
|
|
5
|
+
import { getCurrentWorkingDirectory, resolveDirectory, resolveFile, resolveAbsolutePath } from '../../paths.js'
|
|
6
6
|
import { Plug } from '../../pipe.js'
|
|
7
7
|
import { Run } from '../../run.js'
|
|
8
8
|
import { readFile } from '../../utils/asyncfs.js'
|
|
@@ -34,11 +34,11 @@ export default class ESLint implements Plug<undefined> {
|
|
|
34
34
|
const { directory, configFile } = this._options
|
|
35
35
|
|
|
36
36
|
const cwd = directory ? run.resolve(directory) : getCurrentWorkingDirectory()
|
|
37
|
-
assert(
|
|
37
|
+
assert(resolveDirectory(cwd), `ESLint directory ${$p(cwd)} does not exist`)
|
|
38
38
|
|
|
39
39
|
const overrideConfigFile = configFile ? run.resolve(configFile) : undefined
|
|
40
40
|
if (overrideConfigFile) {
|
|
41
|
-
assert(
|
|
41
|
+
assert(resolveFile(overrideConfigFile), `ESLint configuration ${$p(overrideConfigFile)} does not exist`)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/* Create our ESLint instance */
|
package/src/plugs/exec.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { assert } from '../assert.js'
|
|
|
6
6
|
import { currentRun } from '../async.js'
|
|
7
7
|
import { Files } from '../files.js'
|
|
8
8
|
import { $p, logOptions } from '../log.js'
|
|
9
|
-
import { AbsolutePath, getCurrentWorkingDirectory,
|
|
9
|
+
import { AbsolutePath, getCurrentWorkingDirectory, resolveDirectory } from '../paths.js'
|
|
10
10
|
import { install, Plug } from '../pipe.js'
|
|
11
11
|
import { Run } from '../run.js'
|
|
12
12
|
import { parseOptions, ParseOptions } from '../utils/options.js'
|
|
@@ -156,18 +156,18 @@ async function spawnChild(
|
|
|
156
156
|
} = options
|
|
157
157
|
|
|
158
158
|
const childCwd = cwd ? run.resolve(cwd) : getCurrentWorkingDirectory()
|
|
159
|
-
assert(
|
|
159
|
+
assert(resolveDirectory(childCwd), `Current working directory ${$p(childCwd)} does not exist`)
|
|
160
160
|
|
|
161
161
|
// Figure out the PATH environment variable
|
|
162
162
|
const childPaths: AbsolutePath[] = []
|
|
163
163
|
|
|
164
164
|
// The `.../node_modules/.bin` path relative to the current working dir */
|
|
165
165
|
const baseNodePath = run.resolve('@node_modules', '.bin')
|
|
166
|
-
if (
|
|
166
|
+
if (resolveDirectory(baseNodePath)) childPaths.push(baseNodePath)
|
|
167
167
|
|
|
168
168
|
// The `.../node_bodules/.bin` path relative to the buildDir */
|
|
169
169
|
const buildNodePath = run.resolve('./node_modules', '.bin')
|
|
170
|
-
if (
|
|
170
|
+
if (resolveDirectory(buildNodePath)) childPaths.push(buildNodePath)
|
|
171
171
|
|
|
172
172
|
// Any other paths either from `process.env` or `env` (which overrides it)
|
|
173
173
|
const extraPath = env.PATH || process.env.PATH
|
package/src/plugs/tsc/runner.ts
CHANGED
|
@@ -3,7 +3,7 @@ import ts from 'typescript' // TypeScript does NOT support ESM modules
|
|
|
3
3
|
import { failure } from '../../assert.js'
|
|
4
4
|
import { Files } from '../../files.js'
|
|
5
5
|
import { $p, log } from '../../log.js'
|
|
6
|
-
import { AbsolutePath,
|
|
6
|
+
import { AbsolutePath, resolveFile } from '../../paths.js'
|
|
7
7
|
import { Plug } from '../../pipe.js'
|
|
8
8
|
import { Run } from '../../run.js'
|
|
9
9
|
import { parseOptions, ParseOptions } from '../../utils/options.js'
|
|
@@ -39,9 +39,9 @@ export default class Tsc implements Plug<Files> {
|
|
|
39
39
|
* The "tsconfig" file is either specified, or (if existing) first checked
|
|
40
40
|
* alongside the sources, otherwise checked in the current directory.
|
|
41
41
|
*/
|
|
42
|
-
const sourcesConfig =
|
|
42
|
+
const sourcesConfig = resolveFile(files.directory, 'tsconfig.json')
|
|
43
43
|
const tsconfig = this._tsconfig ? run.resolve(this._tsconfig) :
|
|
44
|
-
sourcesConfig ||
|
|
44
|
+
sourcesConfig || resolveFile(run.resolve('tsconfig.json'))
|
|
45
45
|
|
|
46
46
|
/* Root directory must always exist */
|
|
47
47
|
let rootDir: AbsolutePath
|