@plugjs/tsrun 0.4.29 → 0.5.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.
@@ -0,0 +1,135 @@
1
+ // NodeJS dependencies
2
+ import _module from 'node:module'
3
+ import _path from 'node:path'
4
+
5
+ import {
6
+ CJS,
7
+ ESM,
8
+ esbTranpile,
9
+ logMessage,
10
+ moduleType,
11
+ throwError,
12
+ } from './loader-shared'
13
+
14
+ /* ========================================================================== *
15
+ * CJS VERSION *
16
+ * ========================================================================== */
17
+
18
+ /** The extension handler type, loading CJS modules */
19
+ type ExtensionHandler = (module: NodeJS.Module, filename: string) => void
20
+
21
+ /* Add the `_compile(...)` method to NodeJS' `Module` interface */
22
+ declare global {
23
+ namespace NodeJS {
24
+ interface Module {
25
+ _compile: (contents: string, filename: string) => void
26
+ }
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Add the `_extensions[...]` and `resolveFilename(...)` members to the
32
+ * definition of `node:module`.
33
+ */
34
+ declare module 'node:module' {
35
+ const _extensions: Record<`.${string}`, ExtensionHandler>
36
+ function _resolveFilename(
37
+ request: string,
38
+ parent: _module | undefined,
39
+ isMain: boolean,
40
+ options?: any,
41
+ ): string
42
+ }
43
+
44
+ /* ========================================================================== */
45
+
46
+ const _type = moduleType(CJS)
47
+
48
+ const loader: ExtensionHandler = (module, filename): void => {
49
+ logMessage(CJS, `Attempting to load "${filename}"`)
50
+
51
+ /* Figure our the extension (".ts" or ".cts")... */
52
+ const ext = _path.extname(filename)
53
+
54
+ /* If the file is a ".ts", we need to figure out the default type */
55
+ if (ext === '.ts') {
56
+ /* If the _default_ module type is CJS then load as such! */
57
+ if (_type === ESM) {
58
+ throwError(CJS, `Must use import to load ES Module: ${filename}`, { code: 'ERR_REQUIRE_ESM' })
59
+ }
60
+ } else if (ext !== '.cts') {
61
+ throwError(CJS, `Unsupported filename "${filename}"`)
62
+ }
63
+
64
+ const source = esbTranpile(filename, CJS)
65
+
66
+ /* Let node do its thing, but wrap any error it throws */
67
+ try {
68
+ module._compile(source, filename)
69
+ } catch (cause) {
70
+ // eslint-disable-next-line no-console
71
+ console.error(`Error compiling module "${filename}"`, cause)
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Replace _module._resolveFilename with our own.
77
+ *
78
+ * This is a _HACK BEYOND REDEMPTION_ and I'm ashamed of even _thinking_ about
79
+ * it, but, well, it makes things work.
80
+ *
81
+ * TypeScript allows us to import "./foo.js", and internally resolves this to
82
+ * "./foo.ts" (yeah, nice, right?) and while we normally wouldn't want to deal
83
+ * with this kind of stuff, the "node16" module resolution mode _forces_ us to
84
+ * use this syntax.
85
+ *
86
+ * And we _need_ the "node16" module resolution to properly consume "export
87
+ * conditions" from other packages. Since ESBuild's plugins only work in async
88
+ * mode, changing those import statements on the fly is out of the question, so
89
+ * we need to hack our way into Node's own resolver.
90
+ *
91
+ * See my post: https://twitter.com/ianosh/status/1559484168685379590
92
+ * ESBuild related fix: https://github.com/evanw/esbuild/commit/0cdc005e3d1c765a084f206741bc4bff78e30ec4
93
+ */
94
+ const _oldResolveFilename = _module._resolveFilename
95
+ _module._resolveFilename = function(
96
+ request: string,
97
+ parent: _module | undefined,
98
+ ...args: [ isMain: boolean, options: any ]
99
+ ): any {
100
+ try {
101
+ /* First call the old _resolveFilename to see what Node thinks */
102
+ return _oldResolveFilename.call(this, request, parent, ...args)
103
+ } catch (error: any) {
104
+ /* If the error was anything but "MODULE_NOT_FOUND" bail out */
105
+ if (error.code !== 'MODULE_NOT_FOUND') throw error
106
+
107
+ /* Check if the "request" ends with ".js", ".mjs" or ".cjs" */
108
+ const match = request.match(/(.*)(\.[mc]?js$)/)
109
+
110
+ /*
111
+ * If the file matches our extension, _and_ we have a parent, we simply
112
+ * try with a new extension (e.g. ".js" becomes ".ts")...
113
+ */
114
+ if (parent && match) {
115
+ const [ , name, ext ] = match
116
+ const tsrequest = name + ext!.replace('js', 'ts')
117
+ try {
118
+ const result = _oldResolveFilename.call(this, tsrequest, parent, ...args)
119
+ logMessage(CJS, `Resolution for "${request}" intercepted as "${tsrequest}`)
120
+ return result
121
+ } catch (discard) {
122
+ throw error // throw the _original_ error in this case
123
+ }
124
+ }
125
+
126
+ /* We have no parent, or we don't match our extension, throw! */
127
+ throw error
128
+ }
129
+ }
130
+
131
+ /* ========================================================================== */
132
+
133
+ /* Remember to load our loader for .TS/.CTS as CommonJS modules */
134
+ _module._extensions['.ts'] = _module._extensions['.cts'] = loader
135
+ logMessage(CJS, 'TypeScript loader for CommonJS loaded')
@@ -0,0 +1,230 @@
1
+ import _path from 'node:path'
2
+ import _url from 'node:url'
3
+
4
+ import {
5
+ CJS,
6
+ ESM,
7
+ esbTranpile,
8
+ isDirectory,
9
+ isFile,
10
+ logMessage,
11
+ moduleType,
12
+ } from './loader-shared'
13
+
14
+ /* ========================================================================== *
15
+ * ESM VERSION *
16
+ * ========================================================================== */
17
+
18
+ /** The formats that can be handled by NodeJS' loader */
19
+ type Format = 'builtin' | 'commonjs' | 'json' | 'module' | 'wasm'
20
+
21
+ /* ========================================================================== */
22
+
23
+ /** The type identifying a NodeJS' loader `resolve` hook. */
24
+ type ResolveHook = (
25
+ /** Whatever was requested to be imported (module, relative file, ...). */
26
+ specifier: string,
27
+ /** Context information around this `resolve` hook call. */
28
+ context: ResolveContext,
29
+ /** The subsequent resolve hook in the chain, or the Node.js default one. */
30
+ nextResolve: ResolveNext,
31
+ ) => ResolveResult | Promise<ResolveResult>
32
+
33
+ /** Context information around a `resolve` hook call. */
34
+ interface ResolveContext {
35
+ importAssertions: object
36
+ /** Export conditions of the relevant `package.json`. */
37
+ conditions: string[]
38
+ /** The module importing this one, or undefined if this is the entry point. */
39
+ parentURL?: string | undefined
40
+ }
41
+
42
+ /** The subsequent resolve hook in the chain, or the Node.js default one. */
43
+ type ResolveNext = (specifier: string, context: ResolveContext) => ResolveResult | Promise<ResolveResult>
44
+
45
+ /** A type describing the required results from a `resolve` hook */
46
+ interface ResolveResult {
47
+ /** The absolute URL to which this input resolves. */
48
+ url: string
49
+ /** A format hint to the `load` hook (it might be ignored). */
50
+ format?: Format | null | undefined
51
+ /** A signal that this hook intends to terminate the chain of resolve hooks. */
52
+ shortCircuit?: boolean | undefined
53
+ }
54
+
55
+ /* ========================================================================== */
56
+
57
+ /** The type identifying a NodeJS' loader `load` hook. */
58
+ type LoadHook = (
59
+ /** The URL returned by the resolve chain. */
60
+ url: string,
61
+ /** Context information around this `load` hook call. */
62
+ context: LoadContext,
63
+ /** The subsequent load hook in the chain, or the Node.js default one. */
64
+ nextLoad: LoadNext,
65
+ ) => LoadResult | Promise<LoadResult>
66
+
67
+ /** Context information around a `load` hook call. */
68
+ interface LoadContext {
69
+ importAssertions: object
70
+ /** Export conditions of the relevant `package.json` */
71
+ conditions: string[]
72
+ /** The format hint from the `resolve` hook. */
73
+ format?: ResolveResult['format']
74
+ }
75
+
76
+ /** The subsequent load hook in the chain, or the Node.js default one. */
77
+ type LoadNext = (url: string, context: LoadContext) => LoadResult | Promise<LoadResult>
78
+
79
+ /** A type describing the required results from a `resolve` hook */
80
+ type LoadResult = {
81
+ /** The format of the code being loaded. */
82
+ format: Format
83
+ /** A signal that this hook intends to terminate the chain of load hooks. */
84
+ shortCircuit?: boolean | undefined
85
+ } & ({
86
+ format: 'builtin' | 'commonjs'
87
+ /** When the source is `builtin` or `commonjs` no source must be returned */
88
+ source?: never | undefined
89
+ } | {
90
+ format: 'json' | 'module'
91
+ /** When the source is `json` or `module` the source can include strings */
92
+ source: string | ArrayBuffer | NodeJS.TypedArray
93
+ } | {
94
+ format: 'wasm'
95
+ /** When the source is `wasm` the source must not be a string */
96
+ source: ArrayBuffer | NodeJS.TypedArray
97
+ })
98
+
99
+ /* ========================================================================== */
100
+
101
+ const _type = moduleType(CJS)
102
+
103
+ /**
104
+ * Our main `resolve` hook: here we need to check for a couple of options
105
+ * when importing ""
106
+ */
107
+ export const resolve: ResolveHook = (specifier, context, nextResolve): ResolveResult | Promise<ResolveResult> => {
108
+ logMessage(ESM, `Resolving "${specifier}" from "${context.parentURL}"`)
109
+
110
+ /* We only resolve relative paths ("./xxx" or "../xxx") */
111
+ if (! specifier.match(/^\.\.?\//)) return nextResolve(specifier, context)
112
+
113
+ /* We only resolve if we _do_ have a parent URL and it's a file */
114
+ const parentURL = context.parentURL
115
+ if (! parentURL) return nextResolve(specifier, context)
116
+ if (! parentURL.startsWith('file:')) return nextResolve(specifier, context)
117
+
118
+ /* We only resolve here if the importer is a ".ts" or ".mts" file */
119
+ if (! parentURL.match(/\.m?ts$/)) return nextResolve(specifier, context)
120
+
121
+ /* The resolved URL is the specifier resolved against the parent */
122
+ const url = new URL(specifier, parentURL).href
123
+ const path = _url.fileURLToPath(url)
124
+
125
+ /*
126
+ * Here we are sure that:
127
+ *
128
+ * 1) we are resolving a local path (not a module)
129
+ * 2) the importer is a file, ending with ".ts" or ".mts"
130
+ *
131
+ * Now we can check if "import 'foo'" resolves to:
132
+ *
133
+ * 1) directly to a file, e.g. "import './foo.js'" or "import './foo.mts'"
134
+ * 2) import a "pseudo-JS file", e.g. "import './foo.js'" becomes "import './foo.ts'"
135
+ * 3) imports a file without extension as if it were "import './foo.ts'"
136
+ * 4) imports a directory as in "import './foo/index.ts'"
137
+ *
138
+ * We resolve the _final_ specifier that will be passed to the next resolver
139
+ * for further potential resolution accordingly.
140
+ *
141
+ * We start with the easiest case: is this a real file on the disk?
142
+ */
143
+ if (isFile(path)) {
144
+ logMessage(ESM, `Positive match for "${specifier}" as "${path}" (1)`)
145
+ return nextResolve(specifier, context) // straight on
146
+ }
147
+
148
+ /*
149
+ * TypeScript allows us to import "./foo.js", and internally resolves this to
150
+ * "./foo.ts" (yeah, nice, right?) and while we normally wouldn't want to deal
151
+ * with this kind of stuff, the "node16" module resolution mode _forces_ us to
152
+ * use this syntax.
153
+ */
154
+ const match = specifier.match(/(.*)(\.[mc]?js$)/)
155
+ if (match) {
156
+ const [ , base, ext ] = match
157
+ const tsspecifier = base + ext!.replace('js', 'ts')
158
+ const tsurl = new URL(tsspecifier, parentURL).href
159
+ const tspath = _url.fileURLToPath(tsurl)
160
+
161
+ if (isFile(tspath)) {
162
+ logMessage(ESM, `Positive match for "${specifier}" as "${tspath}" (2)`)
163
+ return nextResolve(tsspecifier, context) // straight on
164
+ }
165
+ }
166
+
167
+ /* Check if the import is actually a file with a ".ts" extension */
168
+ if (isFile(`${path}.ts`)) {
169
+ logMessage(ESM, `Positive match for "${specifier}.ts" as "${path}.ts" (3)`)
170
+ return nextResolve(`${specifier}.ts`, context)
171
+ }
172
+
173
+ /* If the file is a directory, then see if we have an "index.ts" in there */
174
+ if (isDirectory(path)) {
175
+ const file = _path.resolve(path, 'index.ts') // resolve, as path is absolute
176
+ if (isFile(file)) {
177
+ logMessage(ESM, `Positive match for "${specifier}" as "${file}" (4)`)
178
+ const spec = _url.pathToFileURL(file).pathname
179
+ return nextResolve(spec, context)
180
+ }
181
+ }
182
+
183
+ /* There's really nothing else we can do */
184
+ return nextResolve(specifier, context)
185
+ }
186
+
187
+ /** Our main `load` hook */
188
+ export const load: LoadHook = (url, context, nextLoad): LoadResult | Promise<LoadResult> => {
189
+ logMessage(ESM, `Attempting to load "${url}"`)
190
+
191
+ /* We only load from disk, so ignore everything else */
192
+ if (! url.startsWith('file:')) return nextLoad(url, context)
193
+
194
+ /* Figure our the extension (especially ".ts", ".mts" or ".cts")... */
195
+ const ext = url.match(/\.[cm]?ts$/)?.[0]
196
+
197
+ /* Quick and easy bail-outs for non-TS or ".cts" (always `commonjs`) */
198
+ if (! ext) return nextLoad(url, context)
199
+
200
+ if (ext === '.cts') {
201
+ logMessage(ESM, `Switching type from "module" to "commonjs" for "${url}"`)
202
+ logMessage(ESM, 'Please note that named import WILL NOT WORK in this case, as Node.js performs a')
203
+ logMessage(ESM, 'static analisys on the CommonJS source code, and this file is transpiled from.')
204
+ logMessage(ESM, 'TypeScript to CommonJS dynamically.')
205
+ return { format: CJS, shortCircuit: true }
206
+ }
207
+
208
+ /* Convert the url into a file name, any error gets ignored */
209
+ const filename = _url.fileURLToPath(url)
210
+
211
+ /* If the file is a ".ts", we need to figure out the default type */
212
+ if (ext === '.ts') {
213
+ if (_type === CJS) {
214
+ logMessage(ESM, `Switching type from "module" to "commonjs" for "${url}"`)
215
+ logMessage(ESM, 'Please note that named import WILL NOT WORK in this case, as Node.js performs a')
216
+ logMessage(ESM, 'static analisys on the CommonJS source code, and this file is transpiled from.')
217
+ logMessage(ESM, 'TypeScript to CommonJS dynamically.')
218
+ return { format: CJS, shortCircuit: true }
219
+ }
220
+ }
221
+
222
+ /* Transpile with ESBuild and return our source code */
223
+ const source = esbTranpile(filename, ESM)
224
+ return { source, format: ESM, shortCircuit: true }
225
+ }
226
+
227
+ /* ========================================================================== */
228
+
229
+ /* Simply output the fact that we were loaded */
230
+ logMessage(ESM, 'TypeScript loader for ES Modules loaded')
@@ -0,0 +1,220 @@
1
+ /* ========================================================================== *
2
+ * HACK BEYOND REDEMPTION: TRANSPILE .ts FILES (the esm loader) *
3
+ * -------------------------------------------------------------------------- *
4
+ * Use ESBuild to quickly transpile TypeScript files into JavaScript. *
5
+ * *
6
+ * The plan as it stands is as follows: *
7
+ * - `.mts` files always get transpiled to ESM modules *
8
+ * - `.cts` files always get transpiled to CJS modules *
9
+ * - `.ts` files are treanspiled according to what's in `package.json` *
10
+ * *
11
+ * Additionally, when transpiling to ESM modules, we can't rely on the magic *
12
+ * that Node's `require(...)` call uses to figure out which file to import. *
13
+ * We need to _actually verify_ on disk what's the correct file to import. *
14
+ * *
15
+ * This is a single module, only available as ESM, and it will _both_ behave *
16
+ * as a NodeJS' loader, _and_ inject the CJS extension handlers (hack) found *
17
+ * in the `_extensions` of `node:module` (same as `require.extensions`). *
18
+ * ========================================================================== */
19
+
20
+ // NodeJS dependencies
21
+ import _fs from 'node:fs'
22
+ import _path from 'node:path'
23
+ import _util from 'node:util'
24
+
25
+ // ESBuild is the only external dependency
26
+ import _esbuild from 'esbuild'
27
+
28
+ /* ========================================================================== *
29
+ * CONSTANTS AND TYPES *
30
+ * ========================================================================== */
31
+
32
+ /** Supported types from `package.json` */
33
+ export type Type = 'commonjs' | 'module'
34
+ /** Constant identifying a `commonjs` module */
35
+ export const CJS = 'commonjs' as const
36
+ /** Constant identifying an ESM `module` */
37
+ export const ESM = 'module' as const
38
+
39
+ /* ========================================================================== *
40
+ * DEBUGGING AND ERRORS *
41
+ * ========================================================================== */
42
+
43
+ /** Setup debugging */
44
+ const _debugLog = _util.debuglog('plug:ts-loader')
45
+ const _debug = _debugLog.enabled
46
+
47
+ /** Emit some logs if `DEBUG_TS_LOADER` is set to `true` */
48
+ export function logMessage(mode: Type, arg: string, ...args: any []): void {
49
+ if (! _debug) return
50
+
51
+ const t = mode === ESM ? 'esm' : mode === CJS ? 'cjs' : '---'
52
+ _debugLog(`[${t}] ${arg}`, ...args)
53
+ }
54
+
55
+ /** Fail miserably */
56
+ export function throwError(
57
+ mode: Type,
58
+ message: string,
59
+ options: { start?: Function, code?: string, cause?: any } = {},
60
+ ): never {
61
+ const t = mode === ESM ? 'esm' : mode === CJS ? 'cjs' : '---'
62
+ const prefix = `[ts-loader|${t}|pid=${process.pid}]`
63
+
64
+ const { start = throwError, ...extra } = options
65
+ const error = new Error(`${prefix} ${message}`)
66
+ Error.captureStackTrace(error, start)
67
+ Object.assign(error, extra)
68
+
69
+ throw error
70
+ }
71
+
72
+ /* ========================================================================== *
73
+ * MODULE TYPES AND FORCING TYPE *
74
+ * ========================================================================== */
75
+
76
+ /**
77
+ * Determine the current module type to transpile .TS files as looking at the
78
+ * `__TS_LOADER_FORCE_TYPE` environment variable (used by PlugJS and CLI) or,
79
+ * if unspecified, looking at the `type` field in the `package.json` file.
80
+ */
81
+ export function moduleType(mode: Type): Type {
82
+ if (process.env.__TS_LOADER_FORCE_TYPE) {
83
+ const type = process.env.__TS_LOADER_FORCE_TYPE
84
+ if ((type === CJS) || (type === ESM)) {
85
+ logMessage(mode, `Forcing type to "${type}" from environment`)
86
+ return type
87
+ } else {
88
+ throwError(mode, `Invalid type "${process.env.__TS_LOADER_FORCE_TYPE}"`)
89
+ }
90
+ }
91
+
92
+ const _findType = (directory: string): Type => {
93
+ const packageFile = _path.join(directory, 'package.json')
94
+ try {
95
+ const packageData = _fs.readFileSync(packageFile, 'utf-8')
96
+ const packageJson = JSON.parse(packageData)
97
+ const packageType = packageJson.type
98
+ switch (packageType) {
99
+ case undefined:
100
+ logMessage(mode, `File "${packageFile}" does not declare a default type`)
101
+ return CJS
102
+
103
+ case CJS:
104
+ case ESM:
105
+ logMessage(mode, `File "${packageFile}" declares type as "${CJS}"`)
106
+ return packageType
107
+
108
+ default:
109
+ logMessage(mode, `File "${packageFile}" specifies unknown type "${packageType}"`)
110
+ return CJS
111
+ }
112
+ } catch (cause: any) {
113
+ if ((cause.code !== 'ENOENT') && (cause.code !== 'EISDIR')) {
114
+ throwError(mode, `Unable to read or parse "${packageFile}"`, { cause, start: _findType })
115
+ }
116
+ }
117
+
118
+ const parent = _path.dirname(directory)
119
+ if (directory !== parent) return _findType(directory)
120
+
121
+ logMessage(mode, `Type defaulted to "${CJS}"`)
122
+ return CJS
123
+ }
124
+
125
+ return _findType(process.cwd())
126
+ }
127
+
128
+ /* ========================================================================== *
129
+ * ESBUILD HELPERS *
130
+ * ========================================================================== */
131
+
132
+ /**
133
+ * Take an ESBuild `BuildResult` or `BuildFailure` (they both have arrays
134
+ * of `Message` in both `warnings` and `errors`), format them and print them
135
+ * out nicely. Then fail if any error was detected.
136
+ */
137
+ function _esbReport(
138
+ kind: 'error' | 'warning',
139
+ messages: _esbuild.Message[] = [],
140
+ ): void {
141
+ const output = process.stderr
142
+ const options = { color: !!output.isTTY, terminalWidth: output.columns || 80 }
143
+
144
+ const array = _esbuild.formatMessagesSync(messages, { kind, ...options })
145
+ array.forEach((message) => output.write(`${message}\n`))
146
+ }
147
+
148
+ /**
149
+ * Transpile with ESBuild
150
+ */
151
+ export function esbTranpile(filename: string, type: Type): string {
152
+ logMessage(type, `Transpiling "${filename}" as "${type}"`)
153
+
154
+ const [ format, __fileurl ] = type === ESM ?
155
+ [ 'esm', 'import.meta.url' ] as const :
156
+ [ 'cjs', '__filename' ] as const
157
+
158
+ /* ESbuild options */
159
+ const options: _esbuild.TransformOptions = {
160
+ sourcefile: filename, // the original filename we're parsing
161
+ format, // what are we actually transpiling to???
162
+ loader: 'ts', // the format is always "typescript"
163
+ sourcemap: 'inline', // always inline source maps
164
+ sourcesContent: false, // do not include sources content in sourcemap
165
+ platform: 'node', // d'oh! :-)
166
+ minifyWhitespace: true, // https://github.com/evanw/esbuild/releases/tag/v0.16.14
167
+ logLevel: 'silent', // catching those in our _esbReport below
168
+ target: `node${process.versions['node']}`, // target _this_ version
169
+ define: { __fileurl }, // from "globals.d.ts"
170
+ }
171
+
172
+ /* Emit a line on the console when loading in debug mode */
173
+ if (_debug) {
174
+ if (format === 'esm') {
175
+ options.banner = `;(await import('node:util')).debuglog('plug:ts-loader')('[esm] Loaded "%s"', ${__fileurl});`
176
+ } else if (format === 'cjs') {
177
+ options.banner = `;require('node:util').debuglog('plug:ts-loader')('[cjs] Loaded "%s"', ${__fileurl});`
178
+ }
179
+ }
180
+
181
+ /* Transpile our TypeScript file into some JavaScript stuff */
182
+ let result
183
+ try {
184
+ const source = _fs.readFileSync(filename, 'utf-8')
185
+ result = _esbuild.transformSync(source, options)
186
+ } catch (cause: any) {
187
+ _esbReport('error', (cause as _esbuild.TransformFailure).errors)
188
+ _esbReport('warning', (cause as _esbuild.TransformFailure).warnings)
189
+ throwError(type, `ESBuild error transpiling "${filename}"`, { cause, start: esbTranpile })
190
+ }
191
+
192
+ /* Log transpile warnings if debugging */
193
+ if (_debug) _esbReport('warning', result.warnings)
194
+
195
+ /* Done! */
196
+ return result.code
197
+ }
198
+
199
+
200
+ /* ========================================================================== *
201
+ * UTILITIES *
202
+ * ========================================================================== */
203
+
204
+ /* Returns a boolean indicating whether the specified file exists or not */
205
+ export function isFile(path: string): boolean {
206
+ try {
207
+ return _fs.statSync(path).isFile()
208
+ } catch (error) {
209
+ return false
210
+ }
211
+ }
212
+
213
+ /* Returns a boolean indicating whether the specified directory exists or not */
214
+ export function isDirectory(path: string): boolean {
215
+ try {
216
+ return _fs.statSync(path).isDirectory()
217
+ } catch (error) {
218
+ return false
219
+ }
220
+ }
@@ -0,0 +1,5 @@
1
+ import { createRequire, register } from 'node:module'
2
+
3
+ process.setSourceMapsEnabled(true)
4
+ register('./loader-module.mjs', import.meta.url)
5
+ createRequire(import.meta.url)('./loader-commonjs.cjs')