@chialab/esbuild-rna
Advanced tools
Comparing version 0.15.38 to 0.15.39
import path from 'path'; | ||
import crypto from 'crypto'; | ||
import { mkdir, readFile, writeFile } from 'fs/promises'; | ||
import { escapeRegexBody } from '@chialab/node-resolve'; | ||
import { appendSearchParam, escapeRegexBody, getSearchParam } from '@chialab/node-resolve'; | ||
import { loadSourcemap, inlineSourcemap, mergeSourcemaps } from '@chialab/estransform'; | ||
@@ -63,3 +63,3 @@ import { assignToResult, createOutputFile, createResult } from './helpers.js'; | ||
/** | ||
* @typedef {Result & { path: string }} Chunk | ||
* @typedef {Result & { id: string; path: string }} Chunk | ||
*/ | ||
@@ -142,2 +142,13 @@ | ||
/** | ||
* Create hash for the given buffer. | ||
* @param {Buffer} buffer The buffer. | ||
* @returns An hash. | ||
*/ | ||
function createHash(buffer) { | ||
const hash = crypto.createHash('sha1'); | ||
hash.update(/** @type {Buffer} */(buffer)); | ||
return hash.digest('hex').substring(0, 8); | ||
} | ||
/** | ||
* Enrich the esbuild build with a transformation pipeline and emit methods. | ||
@@ -239,7 +250,3 @@ * @param {import('esbuild').PluginBuild} build The esbuild build. | ||
.replace('[dir]', () => path.relative(outBase, path.dirname(filePath))) | ||
.replace('[hash]', () => { | ||
const hash = crypto.createHash('sha1'); | ||
hash.update(/** @type {Buffer} */(buffer)); | ||
return hash.digest('hex').substr(0, 8); | ||
}) | ||
.replace('[hash]', () => createHash(/** @type {Buffer} */(buffer))) | ||
}${path.extname(inputFile)}`; | ||
@@ -365,4 +372,5 @@ }, | ||
isEmittedPath(path) { | ||
const id = getSearchParam(path, 'hash'); | ||
for (const chunk of state.chunks.values()) { | ||
if (chunk.path === path) { | ||
if (chunk.id === id) { | ||
return true; | ||
@@ -372,3 +380,3 @@ } | ||
for (const file of state.files.values()) { | ||
if (file.path === path) { | ||
if (file.id === id) { | ||
return true; | ||
@@ -440,5 +448,7 @@ } | ||
const id = createHash(Buffer.from(buffer)); | ||
const chunkResult = { | ||
...result, | ||
path: `./${path.relative(virtualOutDir, outputFile)}`, | ||
id, | ||
path: appendSearchParam(`./${path.relative(virtualOutDir, outputFile)}`, 'hash', id), | ||
}; | ||
@@ -514,5 +524,8 @@ rnaBuild.files.set(source, chunkResult); | ||
const resolvedOutputFile = path.resolve(rootDir, outFile[0]); | ||
const buffer = result.outputFiles ? result.outputFiles[0].contents : await readFile(resolvedOutputFile); | ||
const id = createHash(Buffer.from(buffer)); | ||
const chunkResult = { | ||
...result, | ||
path: `./${path.relative(virtualOutDir, resolvedOutputFile)}`, | ||
id, | ||
path: appendSearchParam(`./${path.relative(virtualOutDir, resolvedOutputFile)}`, 'hash', id), | ||
}; | ||
@@ -519,0 +532,0 @@ state.chunks.set(options.entryPoint, chunkResult); |
{ | ||
"name": "@chialab/esbuild-rna", | ||
"type": "module", | ||
"version": "0.15.38", | ||
"version": "0.15.39", | ||
"description": "A framework for esbuild plugins with transform and emit capabilities.", | ||
@@ -16,6 +16,2 @@ "main": "lib/index.js", | ||
"keywords": [], | ||
"scripts": { | ||
"types": "rimraf './{types,*.tsbuildinfo}' && tsc -b", | ||
"prepack": "yarn types" | ||
}, | ||
"files": [ | ||
@@ -37,5 +33,4 @@ "lib", | ||
"esbuild": "^0.14.8", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.3.0" | ||
} | ||
} |
@@ -158,2 +158,3 @@ /// <reference types="node" /> | ||
export type Chunk = Result & { | ||
id: string; | ||
path: string; | ||
@@ -160,0 +161,0 @@ }; |
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
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
38835
2
10075
962