Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19b56d1

Browse files
Fa3risfabrice-CS
andauthored
fix(bundle): remove post order of node-resolve (#6353)
* fix(bundle): remove post order of node-resolve node-resolve resolveId hook has been moved to the end of the plugin chain, so other plugins that were meant to be called after resolve some modules incorrectly fixes: #6335 * style: format --------- Co-authored-by: Fabrice Tsiava <[email protected]>
1 parent a3fe474 commit 19b56d1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/compiler/bundle/bundle-output.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rollupJsonPlugin from '@rollup/plugin-json';
33
import rollupNodeResolvePlugin from '@rollup/plugin-node-resolve';
44
import rollupReplacePlugin from '@rollup/plugin-replace';
55
import { createOnWarnFn, isString, loadRollupDiagnostics } from '@utils';
6-
import { PluginContext, rollup, RollupOptions, TreeshakingOptions } from 'rollup';
6+
import { type ObjectHook, PluginContext, rollup, RollupOptions, TreeshakingOptions } from 'rollup';
77

88
import type * as d from '../../declarations';
99
import { lazyComponentPlugin } from '../output-targets/dist-lazy/lazy-component-plugin';
@@ -70,16 +70,18 @@ export const getRollupOptions = (
7070
nodeResolvePlugin.resolve = async function () {
7171
// Investigate if we can use this to leverage Stencil's in-memory fs
7272
};
73-
// @ts-expect-error - handler is defined
73+
74+
assertIsObjectHook(nodeResolvePlugin.resolveId);
75+
// remove default 'post' order
76+
nodeResolvePlugin.resolveId.order = null;
7477
const orgNodeResolveId = nodeResolvePlugin.resolveId.handler;
75-
// @ts-expect-error - handler is defined
7678
const orgNodeResolveId2 = (nodeResolvePlugin.resolveId.handler = async function (importee: string, importer: string) {
7779
const [realImportee, query] = importee.split('?');
78-
// @ts-ignore
7980
const resolved = await orgNodeResolveId.call(
8081
nodeResolvePlugin as unknown as PluginContext,
8182
realImportee,
8283
importer,
84+
// @ts-expect-error - missing required properties but works in practice
8385
{},
8486
);
8587
if (resolved) {
@@ -183,3 +185,7 @@ const getTreeshakeOption = (config: d.ValidatedConfig, bundleOpts: BundleOptions
183185
: false;
184186
return treeshake;
185187
};
188+
189+
function assertIsObjectHook<T>(hook: ObjectHook<T>): asserts hook is { handler: T; order?: 'pre' | 'post' | null } {
190+
if (typeof hook !== 'object') throw new Error(`expected the rollup plugin hook ${hook} to be an object`);
191+
}

0 commit comments

Comments
 (0)