@vanilla-extract/rollup-plugin
Advanced tools
Comparing version 0.0.0-filescope-urls-202283015831 to 0.0.0-fix-hmr-invalidation-20241001041010
@@ -1,1 +0,11 @@ | ||
export * from "./declarations/src/index"; | ||
import { Plugin } from 'rollup'; | ||
import { IdentifierOption, CompileOptions } from '@vanilla-extract/integration'; | ||
interface Options { | ||
identifiers?: IdentifierOption; | ||
cwd?: string; | ||
esbuildOptions?: CompileOptions['esbuildOptions']; | ||
} | ||
declare function vanillaExtractPlugin({ identifiers, cwd, esbuildOptions, }?: Options): Plugin; | ||
export { vanillaExtractPlugin }; |
@@ -18,11 +18,6 @@ 'use strict'; | ||
} = {}) { | ||
const emittedFiles = new Map(); | ||
const isProduction = process.env.NODE_ENV === 'production'; | ||
return { | ||
name: 'vanilla-extract', | ||
buildStart() { | ||
emittedFiles.clear(); | ||
}, | ||
// Transform .css.js to .js | ||
async transform(_code, id) { | ||
@@ -32,6 +27,5 @@ if (!integration.cssFileFilter.test(id)) { | ||
} | ||
const index = id.indexOf('?'); | ||
const filePath = index === -1 ? id : id.substring(0, index); | ||
const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : isProduction ? 'short' : 'debug'; | ||
const identOption = identifiers ?? (isProduction ? 'short' : 'debug'); | ||
const { | ||
@@ -46,7 +40,5 @@ source, | ||
}); | ||
for (const file of watchFiles) { | ||
this.addWatchFile(file); | ||
} | ||
const output = await integration.processVanillaFile({ | ||
@@ -64,9 +56,7 @@ source, | ||
}, | ||
// Resolve .css to external module | ||
async resolveId(id) { | ||
if (!integration.virtualCssFileFilter.test(id)) { | ||
return null; | ||
} // Emit an asset for every virtual css file | ||
} | ||
const { | ||
@@ -76,43 +66,39 @@ fileName, | ||
} = await integration.getSourceFromVirtualCssFile(id); | ||
if (!emittedFiles.get(fileName)) { | ||
const assetId = this.emitFile({ | ||
type: 'asset', | ||
name: fileName, | ||
source | ||
}); | ||
emittedFiles.set(fileName, assetId); | ||
} // Resolve to a temporary external module | ||
return { | ||
id: fileName, | ||
external: true | ||
external: true, | ||
meta: { | ||
css: source | ||
} | ||
}; | ||
}, | ||
// Emit .css assets | ||
moduleParsed(moduleInfo) { | ||
moduleInfo.importedIdResolutions.forEach(resolution => { | ||
if (resolution.meta.css) { | ||
resolution.meta.assetId = this.emitFile({ | ||
type: 'asset', | ||
name: resolution.id, | ||
source: resolution.meta.css | ||
}); | ||
} | ||
}); | ||
}, | ||
// Replace .css import paths with relative paths to emitted css files | ||
renderChunk(code, chunkInfo) { | ||
var _chunkInfo$map; | ||
// For all imports in this chunk that we have emitted files for... | ||
const importsToReplace = chunkInfo.imports.filter(fileName => emittedFiles.get(fileName)); | ||
if (!importsToReplace.length) { | ||
return null; | ||
} // ...replace import paths with relative paths to emitted css files | ||
const chunkPath = dirname(chunkInfo.fileName); | ||
const output = importsToReplace.reduce((codeResult, importPath) => { | ||
const assetId = emittedFiles.get(importPath); | ||
const assetName = this.getFileName(assetId); | ||
const fixedImportPath = `./${normalize(relative(chunkPath, assetName))}`; | ||
return codeResult.replace(importPath, fixedImportPath); | ||
const output = chunkInfo.imports.reduce((codeResult, importPath) => { | ||
const moduleInfo = this.getModuleInfo(importPath); | ||
if (!(moduleInfo !== null && moduleInfo !== void 0 && moduleInfo.meta.assetId)) { | ||
return codeResult; | ||
} | ||
const assetPath = this.getFileName(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.meta.assetId); | ||
const relativeAssetPath = `./${normalize(relative(chunkPath, assetPath))}`; | ||
return codeResult.replace(importPath, relativeAssetPath); | ||
}, code); | ||
return { | ||
code: output, | ||
map: (_chunkInfo$map = chunkInfo.map) !== null && _chunkInfo$map !== void 0 ? _chunkInfo$map : null | ||
map: null | ||
}; | ||
} | ||
}; | ||
@@ -119,0 +105,0 @@ } |
@@ -18,10 +18,5 @@ 'use strict'; | ||
} = {}) { | ||
const emittedFiles = new Map(); | ||
return { | ||
name: 'vanilla-extract', | ||
buildStart() { | ||
emittedFiles.clear(); | ||
}, | ||
// Transform .css.js to .js | ||
async transform(_code, id) { | ||
@@ -31,6 +26,5 @@ if (!integration.cssFileFilter.test(id)) { | ||
} | ||
const index = id.indexOf('?'); | ||
const filePath = index === -1 ? id : id.substring(0, index); | ||
const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : 'short' ; | ||
const identOption = identifiers ?? ('short' ); | ||
const { | ||
@@ -45,7 +39,5 @@ source, | ||
}); | ||
for (const file of watchFiles) { | ||
this.addWatchFile(file); | ||
} | ||
const output = await integration.processVanillaFile({ | ||
@@ -63,9 +55,7 @@ source, | ||
}, | ||
// Resolve .css to external module | ||
async resolveId(id) { | ||
if (!integration.virtualCssFileFilter.test(id)) { | ||
return null; | ||
} // Emit an asset for every virtual css file | ||
} | ||
const { | ||
@@ -75,43 +65,39 @@ fileName, | ||
} = await integration.getSourceFromVirtualCssFile(id); | ||
if (!emittedFiles.get(fileName)) { | ||
const assetId = this.emitFile({ | ||
type: 'asset', | ||
name: fileName, | ||
source | ||
}); | ||
emittedFiles.set(fileName, assetId); | ||
} // Resolve to a temporary external module | ||
return { | ||
id: fileName, | ||
external: true | ||
external: true, | ||
meta: { | ||
css: source | ||
} | ||
}; | ||
}, | ||
// Emit .css assets | ||
moduleParsed(moduleInfo) { | ||
moduleInfo.importedIdResolutions.forEach(resolution => { | ||
if (resolution.meta.css) { | ||
resolution.meta.assetId = this.emitFile({ | ||
type: 'asset', | ||
name: resolution.id, | ||
source: resolution.meta.css | ||
}); | ||
} | ||
}); | ||
}, | ||
// Replace .css import paths with relative paths to emitted css files | ||
renderChunk(code, chunkInfo) { | ||
var _chunkInfo$map; | ||
// For all imports in this chunk that we have emitted files for... | ||
const importsToReplace = chunkInfo.imports.filter(fileName => emittedFiles.get(fileName)); | ||
if (!importsToReplace.length) { | ||
return null; | ||
} // ...replace import paths with relative paths to emitted css files | ||
const chunkPath = dirname(chunkInfo.fileName); | ||
const output = importsToReplace.reduce((codeResult, importPath) => { | ||
const assetId = emittedFiles.get(importPath); | ||
const assetName = this.getFileName(assetId); | ||
const fixedImportPath = `./${normalize(relative(chunkPath, assetName))}`; | ||
return codeResult.replace(importPath, fixedImportPath); | ||
const output = chunkInfo.imports.reduce((codeResult, importPath) => { | ||
const moduleInfo = this.getModuleInfo(importPath); | ||
if (!(moduleInfo !== null && moduleInfo !== void 0 && moduleInfo.meta.assetId)) { | ||
return codeResult; | ||
} | ||
const assetPath = this.getFileName(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.meta.assetId); | ||
const relativeAssetPath = `./${normalize(relative(chunkPath, assetPath))}`; | ||
return codeResult.replace(importPath, relativeAssetPath); | ||
}, code); | ||
return { | ||
code: output, | ||
map: (_chunkInfo$map = chunkInfo.map) !== null && _chunkInfo$map !== void 0 ? _chunkInfo$map : null | ||
map: null | ||
}; | ||
} | ||
}; | ||
@@ -118,0 +104,0 @@ } |
@@ -14,11 +14,6 @@ import { cssFileFilter, compile, processVanillaFile, virtualCssFileFilter, getSourceFromVirtualCssFile } from '@vanilla-extract/integration'; | ||
} = {}) { | ||
const emittedFiles = new Map(); | ||
const isProduction = process.env.NODE_ENV === 'production'; | ||
return { | ||
name: 'vanilla-extract', | ||
buildStart() { | ||
emittedFiles.clear(); | ||
}, | ||
// Transform .css.js to .js | ||
async transform(_code, id) { | ||
@@ -28,6 +23,5 @@ if (!cssFileFilter.test(id)) { | ||
} | ||
const index = id.indexOf('?'); | ||
const filePath = index === -1 ? id : id.substring(0, index); | ||
const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : isProduction ? 'short' : 'debug'; | ||
const identOption = identifiers ?? (isProduction ? 'short' : 'debug'); | ||
const { | ||
@@ -42,7 +36,5 @@ source, | ||
}); | ||
for (const file of watchFiles) { | ||
this.addWatchFile(file); | ||
} | ||
const output = await processVanillaFile({ | ||
@@ -60,9 +52,7 @@ source, | ||
}, | ||
// Resolve .css to external module | ||
async resolveId(id) { | ||
if (!virtualCssFileFilter.test(id)) { | ||
return null; | ||
} // Emit an asset for every virtual css file | ||
} | ||
const { | ||
@@ -72,43 +62,39 @@ fileName, | ||
} = await getSourceFromVirtualCssFile(id); | ||
if (!emittedFiles.get(fileName)) { | ||
const assetId = this.emitFile({ | ||
type: 'asset', | ||
name: fileName, | ||
source | ||
}); | ||
emittedFiles.set(fileName, assetId); | ||
} // Resolve to a temporary external module | ||
return { | ||
id: fileName, | ||
external: true | ||
external: true, | ||
meta: { | ||
css: source | ||
} | ||
}; | ||
}, | ||
// Emit .css assets | ||
moduleParsed(moduleInfo) { | ||
moduleInfo.importedIdResolutions.forEach(resolution => { | ||
if (resolution.meta.css) { | ||
resolution.meta.assetId = this.emitFile({ | ||
type: 'asset', | ||
name: resolution.id, | ||
source: resolution.meta.css | ||
}); | ||
} | ||
}); | ||
}, | ||
// Replace .css import paths with relative paths to emitted css files | ||
renderChunk(code, chunkInfo) { | ||
var _chunkInfo$map; | ||
// For all imports in this chunk that we have emitted files for... | ||
const importsToReplace = chunkInfo.imports.filter(fileName => emittedFiles.get(fileName)); | ||
if (!importsToReplace.length) { | ||
return null; | ||
} // ...replace import paths with relative paths to emitted css files | ||
const chunkPath = dirname(chunkInfo.fileName); | ||
const output = importsToReplace.reduce((codeResult, importPath) => { | ||
const assetId = emittedFiles.get(importPath); | ||
const assetName = this.getFileName(assetId); | ||
const fixedImportPath = `./${normalize(relative(chunkPath, assetName))}`; | ||
return codeResult.replace(importPath, fixedImportPath); | ||
const output = chunkInfo.imports.reduce((codeResult, importPath) => { | ||
const moduleInfo = this.getModuleInfo(importPath); | ||
if (!(moduleInfo !== null && moduleInfo !== void 0 && moduleInfo.meta.assetId)) { | ||
return codeResult; | ||
} | ||
const assetPath = this.getFileName(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.meta.assetId); | ||
const relativeAssetPath = `./${normalize(relative(chunkPath, assetPath))}`; | ||
return codeResult.replace(importPath, relativeAssetPath); | ||
}, code); | ||
return { | ||
code: output, | ||
map: (_chunkInfo$map = chunkInfo.map) !== null && _chunkInfo$map !== void 0 ? _chunkInfo$map : null | ||
map: null | ||
}; | ||
} | ||
}; | ||
@@ -115,0 +101,0 @@ } |
{ | ||
"name": "@vanilla-extract/rollup-plugin", | ||
"version": "0.0.0-filescope-urls-202283015831", | ||
"version": "0.0.0-fix-hmr-invalidation-20241001041010", | ||
"description": "Zero-runtime Stylesheets-in-TypeScript", | ||
"main": "dist/vanilla-extract-rollup-plugin.cjs.js", | ||
"module": "dist/vanilla-extract-rollup-plugin.esm.js", | ||
"types": "dist/vanilla-extract-rollup-plugin.cjs.d.ts", | ||
"files": [ | ||
@@ -18,15 +19,15 @@ "/dist" | ||
"dependencies": { | ||
"@vanilla-extract/integration": "^0.0.0-filescope-urls-202283015831" | ||
"@vanilla-extract/integration": "^0.0.0-fix-hmr-invalidation-20241001041010" | ||
}, | ||
"devDependencies": { | ||
"@fixtures/themed": "*", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@vanilla-extract/css": "^0.0.0-filescope-urls-202283015831", | ||
"esbuild": "^0.11.16", | ||
"rollup": "^2.7.0", | ||
"rollup-plugin-esbuild": "^4.9.1" | ||
"@rollup/plugin-json": "^6.1.0", | ||
"esbuild": "~0.23.1", | ||
"rollup": "^4.20.0", | ||
"rollup-plugin-esbuild": "^6.1.1", | ||
"@fixtures/themed": "0.0.0-fix-hmr-invalidation-20241001041010", | ||
"@vanilla-extract/css": "^0.0.0-fix-hmr-invalidation-20241001041010" | ||
}, | ||
"peerDependencies": { | ||
"rollup": "^2.0.0" | ||
"rollup": "^2.0.0 || ^3.0.0 || ^4.0.0" | ||
} | ||
} |
306
14288
- Removedrollup@2.79.2(transitive)
Updated@vanilla-extract/integration@^0.0.0-fix-hmr-invalidation-20241001041010