@web/dev-server-rollup
Advanced tools
Comparing version 0.0.0-canary-20230222141205 to 0.0.0-canary-20230316175616
import { DevServerCoreConfig, FSWatcher, Plugin as WdsPlugin, Context, ResolveOptions } from '@web/dev-server-core'; | ||
import { PluginContext, MinimalPluginContext, TransformPluginContext, CustomPluginOptions, ModuleInfo } from 'rollup'; | ||
export declare function createRollupPluginContextAdapter<T extends PluginContext | MinimalPluginContext | TransformPluginContext>(pluginContext: T, wdsPlugin: WdsPlugin, config: DevServerCoreConfig, fileWatcher: FSWatcher, context: Context, pluginMetaPerModule: Map<string, CustomPluginOptions>): T & { | ||
getModuleInfo(id: string): ModuleInfo; | ||
getModuleInfo(id: string): Partial<ModuleInfo>; | ||
addWatchFile(id: string): void; | ||
@@ -6,0 +6,0 @@ emitAsset(): never; |
@@ -64,8 +64,21 @@ "use strict"; | ||
// call the options and buildStart hooks | ||
const transformedOptions = (_b = (await ((_a = rollupPlugin.options) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContexts.minimalPluginContext, rollupInputOptions)))) !== null && _b !== void 0 ? _b : rollupInputOptions; | ||
(_c = rollupPlugin.buildStart) === null || _c === void 0 ? void 0 : _c.call(rollupPluginContexts.pluginContext, rollupPluginContexts.normalizedInputOptions); | ||
if (transformedOptions && transformedOptions.plugins) { | ||
let transformedOptions; | ||
if (typeof rollupPlugin.options === 'function') { | ||
transformedOptions = (_b = (await ((_a = rollupPlugin.options) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContexts.minimalPluginContext, rollupInputOptions)))) !== null && _b !== void 0 ? _b : rollupInputOptions; | ||
} | ||
else { | ||
transformedOptions = rollupInputOptions; | ||
} | ||
if (typeof rollupPlugin.buildStart === 'function') { | ||
(_c = rollupPlugin.buildStart) === null || _c === void 0 ? void 0 : _c.call(rollupPluginContexts.pluginContext, rollupPluginContexts.normalizedInputOptions); | ||
} | ||
if (transformedOptions && | ||
transformedOptions.plugins && | ||
Array.isArray(transformedOptions.plugins)) { | ||
for (const subPlugin of transformedOptions.plugins) { | ||
if (subPlugin && subPlugin.resolveId) { | ||
idResolvers.push(subPlugin.resolveId); | ||
if (subPlugin && !Array.isArray(subPlugin)) { | ||
const resolveId = subPlugin.resolveId; | ||
if (resolveId) { | ||
idResolvers.push(resolveId); | ||
} | ||
} | ||
@@ -87,3 +100,3 @@ } | ||
async resolveImport({ source, context, code, column, line, resolveOptions }) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
if (context.response.is('html') && source.startsWith('�')) { | ||
@@ -101,3 +114,7 @@ // when serving HTML a null byte gets parsed as an unknown character | ||
} | ||
if (!injectedFilePath && !path_1.default.isAbsolute(source) && whatwg_url_1.default.parseURL(source) != null) { | ||
const isVirtualModule = source.startsWith('\0'); | ||
if (!injectedFilePath && | ||
!path_1.default.isAbsolute(source) && | ||
whatwg_url_1.default.parseURL(source) != null && | ||
!isVirtualModule) { | ||
// don't resolve relative and valid urls | ||
@@ -134,3 +151,4 @@ return source; | ||
for (const idResolver of idResolvers) { | ||
result = await idResolver.call(rollupPluginContext, resolvableImport, filePath, Object.assign(Object.assign({}, resolveOptions), { isEntry: false })); | ||
const idResolverHandler = typeof idResolver === 'function' ? idResolver : idResolver.handler; | ||
result = await idResolverHandler.call(rollupPluginContext, resolvableImport, filePath, Object.assign(Object.assign({}, resolveOptions), { assertions: Object.assign({}, ((_c = resolveOptions === null || resolveOptions === void 0 ? void 0 : resolveOptions.assertions) !== null && _c !== void 0 ? _c : {})), isEntry: false })); | ||
if (result) { | ||
@@ -247,3 +265,6 @@ break; | ||
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule); | ||
const result = await ((_a = rollupPlugin.load) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, filePath)); | ||
let result; | ||
if (typeof rollupPlugin.load === 'function') { | ||
result = await ((_a = rollupPlugin.load) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, filePath)); | ||
} | ||
if (typeof result === 'string') { | ||
@@ -274,3 +295,6 @@ return { body: result, type: 'js' }; | ||
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule); | ||
const result = await ((_a = rollupPlugin.transform) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, context.body, filePath)); | ||
let result; | ||
if (typeof rollupPlugin.transform === 'function') { | ||
result = await ((_a = rollupPlugin.transform) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, context.body, filePath)); | ||
} | ||
let transformedCode = undefined; | ||
@@ -303,3 +327,6 @@ if (typeof result === 'string') { | ||
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule); | ||
const result = await ((_b = rollupPlugin.transform) === null || _b === void 0 ? void 0 : _b.call(rollupPluginContext, code, filePath)); | ||
let result; | ||
if (typeof rollupPlugin.transform === 'function') { | ||
result = await ((_b = rollupPlugin.transform) === null || _b === void 0 ? void 0 : _b.call(rollupPluginContext, code, filePath)); | ||
} | ||
let transformedCode = undefined; | ||
@@ -338,3 +365,5 @@ if (typeof result === 'string') { | ||
throw new Error(`Missing info for module ${filePath}`); | ||
(_a = rollupPlugin.moduleParsed) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, info); | ||
if (typeof rollupPlugin.moduleParsed === 'function') { | ||
(_a = rollupPlugin.moduleParsed) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, info); | ||
} | ||
}, | ||
@@ -341,0 +370,0 @@ }; |
{ | ||
"name": "@web/dev-server-rollup", | ||
"version": "0.0.0-canary-20230222141205", | ||
"version": "0.0.0-canary-20230316175616", | ||
"publishConfig": { | ||
@@ -50,7 +50,7 @@ "access": "public" | ||
"dependencies": { | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"@web/dev-server-core": "0.0.0-canary-20230222141205", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@web/dev-server-core": "^0.4.0", | ||
"nanocolors": "^0.2.1", | ||
"parse5": "^6.0.1", | ||
"rollup": "^2.67.0", | ||
"rollup": "^3.15.0", | ||
"whatwg-url": "^11.0.0" | ||
@@ -60,15 +60,15 @@ }, | ||
"@babel/plugin-transform-template-literals": "^7.12.1", | ||
"@rollup/plugin-alias": "^3.1.1", | ||
"@rollup/plugin-babel": "^5.2.2", | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-replace": "^3.0.0", | ||
"@rollup/plugin-alias": "^4.0.3", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@rollup/plugin-commonjs": "^24.0.1", | ||
"@rollup/plugin-replace": "^5.0.2", | ||
"@types/parse5": "^6.0.1", | ||
"@types/whatwg-url": "^11.0.0", | ||
"@web/test-runner-chrome": "^0.11.0", | ||
"@web/test-runner-core": "0.0.0-canary-20230222141205", | ||
"@web/test-runner-core": "^0.10.28", | ||
"chai": "^4.2.0", | ||
"node-fetch": "3.0.0-beta.9", | ||
"postcss": "^8.0.0", | ||
"rollup-plugin-postcss": "^4.0.0" | ||
"rollup-plugin-postcss": "^4.0.2" | ||
} | ||
} |
@@ -30,3 +30,3 @@ import path from 'path'; | ||
getModuleInfo(id: string): ModuleInfo { | ||
getModuleInfo(id: string): Partial<ModuleInfo> { | ||
return { | ||
@@ -33,0 +33,0 @@ id, |
@@ -20,8 +20,3 @@ /* eslint-disable no-control-regex */ | ||
import { parse as parseHtml, serialize as serializeHtml } from 'parse5'; | ||
import { | ||
CustomPluginOptions, | ||
Plugin as RollupPlugin, | ||
TransformPluginContext, | ||
ResolveIdHook, | ||
} from 'rollup'; | ||
import { CustomPluginOptions, Plugin as RollupPlugin, TransformPluginContext } from 'rollup'; | ||
import { InputOptions } from 'rollup'; | ||
@@ -81,3 +76,3 @@ import { red, cyan } from 'nanocolors'; | ||
let rootDir: string; | ||
let idResolvers: ResolveIdHook[] = []; | ||
let idResolvers: Array<Required<RollupPlugin>['resolveId']> = []; | ||
@@ -105,16 +100,31 @@ function savePluginMeta( | ||
// call the options and buildStart hooks | ||
const transformedOptions = | ||
(await rollupPlugin.options?.call( | ||
rollupPluginContexts.minimalPluginContext, | ||
rollupInputOptions, | ||
)) ?? rollupInputOptions; | ||
rollupPlugin.buildStart?.call( | ||
rollupPluginContexts.pluginContext, | ||
rollupPluginContexts.normalizedInputOptions, | ||
); | ||
let transformedOptions; | ||
if (typeof rollupPlugin.options === 'function') { | ||
transformedOptions = | ||
(await rollupPlugin.options?.call( | ||
rollupPluginContexts.minimalPluginContext, | ||
rollupInputOptions, | ||
)) ?? rollupInputOptions; | ||
} else { | ||
transformedOptions = rollupInputOptions; | ||
} | ||
if (typeof rollupPlugin.buildStart === 'function') { | ||
rollupPlugin.buildStart?.call( | ||
rollupPluginContexts.pluginContext, | ||
rollupPluginContexts.normalizedInputOptions, | ||
); | ||
} | ||
if (transformedOptions && transformedOptions.plugins) { | ||
if ( | ||
transformedOptions && | ||
transformedOptions.plugins && | ||
Array.isArray(transformedOptions.plugins) | ||
) { | ||
for (const subPlugin of transformedOptions.plugins) { | ||
if (subPlugin && subPlugin.resolveId) { | ||
idResolvers.push(subPlugin.resolveId); | ||
if (subPlugin && !Array.isArray(subPlugin)) { | ||
const resolveId = (subPlugin as RollupPlugin).resolveId; | ||
if (resolveId) { | ||
idResolvers.push(resolveId); | ||
} | ||
} | ||
@@ -154,3 +164,9 @@ } | ||
if (!injectedFilePath && !path.isAbsolute(source) && whatwgUrl.parseURL(source) != null) { | ||
const isVirtualModule = source.startsWith('\0'); | ||
if ( | ||
!injectedFilePath && | ||
!path.isAbsolute(source) && | ||
whatwgUrl.parseURL(source) != null && | ||
!isVirtualModule | ||
) { | ||
// don't resolve relative and valid urls | ||
@@ -201,4 +217,9 @@ return source; | ||
for (const idResolver of idResolvers) { | ||
result = await idResolver.call(rollupPluginContext, resolvableImport, filePath, { | ||
const idResolverHandler = | ||
typeof idResolver === 'function' ? idResolver : idResolver.handler; | ||
result = await idResolverHandler.call(rollupPluginContext, resolvableImport, filePath, { | ||
...resolveOptions, | ||
assertions: { | ||
...((resolveOptions?.assertions as Record<string, string>) ?? {}), | ||
}, | ||
isEntry: false, | ||
@@ -349,3 +370,6 @@ }); | ||
const result = await rollupPlugin.load?.call(rollupPluginContext, filePath); | ||
let result; | ||
if (typeof rollupPlugin.load === 'function') { | ||
result = await rollupPlugin.load?.call(rollupPluginContext, filePath); | ||
} | ||
@@ -387,7 +411,10 @@ if (typeof result === 'string') { | ||
const result = await rollupPlugin.transform?.call( | ||
rollupPluginContext as TransformPluginContext, | ||
context.body as string, | ||
filePath, | ||
); | ||
let result; | ||
if (typeof rollupPlugin.transform === 'function') { | ||
result = await rollupPlugin.transform?.call( | ||
rollupPluginContext as TransformPluginContext, | ||
context.body as string, | ||
filePath, | ||
); | ||
} | ||
@@ -440,7 +467,10 @@ let transformedCode: string | undefined = undefined; | ||
const result = await rollupPlugin.transform?.call( | ||
rollupPluginContext as TransformPluginContext, | ||
code, | ||
filePath, | ||
); | ||
let result; | ||
if (typeof rollupPlugin.transform === 'function') { | ||
result = await rollupPlugin.transform?.call( | ||
rollupPluginContext as TransformPluginContext, | ||
code, | ||
filePath, | ||
); | ||
} | ||
@@ -489,3 +519,5 @@ let transformedCode: string | undefined = undefined; | ||
if (!info) throw new Error(`Missing info for module ${filePath}`); | ||
rollupPlugin.moduleParsed?.call(rollupPluginContext as TransformPluginContext, info); | ||
if (typeof rollupPlugin.moduleParsed === 'function') { | ||
rollupPlugin.moduleParsed?.call(rollupPluginContext as TransformPluginContext, info); | ||
} | ||
}, | ||
@@ -492,0 +524,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
88115
1425
+ Added@rollup/plugin-node-resolve@15.3.0(transitive)
+ Added@rollup/pluginutils@5.1.2(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/resolve@1.20.2(transitive)
+ Added@web/dev-server-core@0.4.1(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedisbinaryfile@5.0.2(transitive)
+ Addedrollup@3.29.5(transitive)
- Removed@rollup/plugin-node-resolve@13.3.0(transitive)
- Removed@rollup/pluginutils@3.1.0(transitive)
- Removed@types/estree@0.0.39(transitive)
- Removed@types/resolve@1.17.1(transitive)
- Removed@web/dev-server-core@0.0.0-canary-20230222141205(transitive)
- Removedbuiltin-modules@3.3.0(transitive)
- Removedestree-walker@1.0.1(transitive)
- Removedis-builtin-module@3.2.1(transitive)
- Removedisbinaryfile@4.0.10(transitive)
- Removedrollup@2.79.2(transitive)
Updated@web/dev-server-core@^0.4.0
Updatedrollup@^3.15.0