@node-loaders/esbuild
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -1,4 +0,3 @@ | ||
import { type TransformOptions } from 'esbuild'; | ||
import LoaderBase, { type LoadContext, type LoadedModule, type LoaderBaseOptions, type NextResolve, type NextLoad, type ResolveContext, type ResolvedModule } from '@node-loaders/core'; | ||
import { EsbuildCache } from './cache.js'; | ||
import { EsbuildSources } from './esbuild-sources.js'; | ||
export type EsbuildLoaderOptions = LoaderBaseOptions & { | ||
@@ -9,4 +8,3 @@ allowDefaults?: boolean; | ||
allowDefaults: boolean; | ||
sourceMapEnabled: boolean; | ||
cache: EsbuildCache; | ||
esbuildSources: EsbuildSources; | ||
constructor(options?: EsbuildLoaderOptions); | ||
@@ -17,4 +15,2 @@ lookForExistingEsbuildFilePath(filePath: string): Promise<string | undefined>; | ||
_load(url: string, context: LoadContext, nextLoad: NextLoad): Promise<LoadedModule>; | ||
transform(filePath: string, format: string): Promise<string>; | ||
getOptions(options: TransformOptions & Required<Pick<TransformOptions, 'sourcefile'>>): TransformOptions; | ||
} |
@@ -1,15 +0,9 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
import { dirname } from 'node:path'; | ||
import process from 'node:process'; | ||
import { fileURLToPath, pathToFileURL } from 'node:url'; | ||
import { transform } from 'esbuild'; | ||
import { getTsconfig } from 'get-tsconfig'; | ||
import LoaderBase, { isFileSpecifier, isPackageJsonImportSpecifier, } from '@node-loaders/core'; | ||
import { existingFile, lookForDefaultModule, specifierToFilePath, detectPackageJsonType } from '@node-loaders/resolve'; | ||
import { detectFormatForEsbuildFileExtension, isEsbuildExtensionSupported, lookForEsbuildReplacementFile } from './esbuild-module.js'; | ||
import { EsbuildCache } from './cache.js'; | ||
import { pathToFileURL } from 'node:url'; | ||
import LoaderBase, { isFileSpecifier, isPackageJsonImportSpecifier, specifierToFilePath, } from '@node-loaders/core'; | ||
import { existingFile, lookForDefaultModule } from '@node-loaders/resolve'; | ||
import { detectFormatForEsbuildFileExtension, isEsbuildExtensionSupported, lookForEsbuildReplacementFile } from './esbuild-support.js'; | ||
import { EsbuildSources } from './esbuild-sources.js'; | ||
export default class EsbuildLoader extends LoaderBase { | ||
allowDefaults; | ||
sourceMapEnabled = false; | ||
cache = new EsbuildCache(); | ||
esbuildSources = new EsbuildSources(); | ||
constructor(options = {}) { | ||
@@ -73,10 +67,3 @@ // We want builtin modules and package import to pass through | ||
if (isEsbuildExtensionSupported(url)) { | ||
let cachedfile = this.cache.get(url); | ||
if (!cachedfile) { | ||
const filePath = fileURLToPath(url); | ||
const format = context.format ?? (await detectPackageJsonType(filePath)); | ||
const source = await this.transform(filePath, format); | ||
cachedfile = { format, source }; | ||
this.cache.set(url, cachedfile); | ||
} | ||
const cachedfile = await this.esbuildSources.getSource(url, context.format); | ||
return { | ||
@@ -90,33 +77,3 @@ format: cachedfile.format, | ||
} | ||
async transform(filePath, format) { | ||
this.log(`Transforming ${filePath}`); | ||
const code = await readFile(filePath); | ||
const esbuildFormat = format === 'module' ? 'esm' : 'cjs'; | ||
// We are transpiling, enable sourcemap is available | ||
if (!this.sourceMapEnabled) { | ||
if ('setSourceMapsEnabled' in process && typeof Error.prepareStackTrace !== 'function') { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
process.setSourceMapsEnabled(true); | ||
} | ||
this.sourceMapEnabled = true; | ||
} | ||
const { code: source } = await transform(code.toString(), this.getOptions({ | ||
sourcefile: filePath, | ||
format: esbuildFormat, | ||
})); | ||
return source; | ||
} | ||
getOptions(options) { | ||
const tsconfigRaw = getTsconfig(dirname(options.sourcefile))?.config; | ||
return { | ||
loader: 'default', | ||
minifyWhitespace: true, | ||
keepNames: true, | ||
sourcemap: 'inline', | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
tsconfigRaw: tsconfigRaw, | ||
...options, | ||
}; | ||
} | ||
} | ||
//# sourceMappingURL=esbuild-loader.js.map |
{ | ||
"name": "@node-loaders/esbuild", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"private": false, | ||
@@ -25,6 +25,5 @@ "keywords": [ | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./compat": "./dist/compat.js", | ||
"./node14": "./dist/node14.js", | ||
"./compat-node14": "./dist/compat-node14.js" | ||
".": "./dist/index-default.js", | ||
"./node14": "./dist/index-node14.js", | ||
"./esm": "./dist/index-esm.js" | ||
}, | ||
@@ -45,4 +44,4 @@ "files": [ | ||
"dependencies": { | ||
"@node-loaders/core": "^0.4.0", | ||
"@node-loaders/resolve": "^0.3.0", | ||
"@node-loaders/core": "^0.5.0", | ||
"@node-loaders/resolve": "^0.4.0", | ||
"esbuild": "^0.15.16", | ||
@@ -57,3 +56,3 @@ "get-tsconfig": "^4.2.0" | ||
}, | ||
"gitHead": "d4868a4e12af38b83a843693a5e294a3a889b07c" | ||
"gitHead": "2839739754eb82b94488fe9e0765cd8623fff860" | ||
} |
@@ -11,2 +11,13 @@ # @node-loaders/esbuild | ||
## ESM/strict mode | ||
Native ECMAScript support requires imports with extensions, while commonjs files allows directory imports and extensionless files. | ||
To match this behaviour, use: | ||
- `@node-loaders/esbuild/strict` for esm with strict extension imports with loose require support. | ||
- `@node-loaders/esbuild/esm` for esm with strict extension imports without require support. | ||
No strict support export is provided for node14 by default. | ||
### Node 14 | ||
@@ -13,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36395
27
462
37
1
+ Added@node-loaders/core@0.5.0(transitive)
+ Added@node-loaders/resolve@0.4.0(transitive)
- Removed@node-loaders/core@0.4.0(transitive)
- Removed@node-loaders/resolve@0.3.0(transitive)
Updated@node-loaders/core@^0.5.0
Updated@node-loaders/resolve@^0.4.0