-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: build pipeline #8088
refactor: build pipeline #8088
Conversation
|
const headers = new Headers(); | ||
headers.set('X-Astro-Encoding', response.encoding); | ||
return new Response(response.body, { | ||
headers, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we could store the encoding
coming from a simple
response using an internal header. What do you think? When generating a page, we read it and use it when we write the file to file system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80% of the code comes from plugin-ssr.ts
.
48be659
to
090ac80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Glad to see the manifest changes and a whole bunch of cleanup.
const headers = new Headers(); | ||
headers.set('X-Astro-Encoding', response.encoding); | ||
return new Response(response.body, { | ||
headers, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the changes so far. Thanks for addressing my comments from the last PR!
Have some small nits below.
const imports = []; | ||
const contents = []; | ||
const exports = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we could type this as string[]
@@ -64,6 +58,8 @@ import type { | |||
StylesheetAsset, | |||
} from './types'; | |||
import { getTimeStat } from './util.js'; | |||
import { BuildPipeline } from './buildPipeline.js'; | |||
import type { BufferEncoding } from 'vfile'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can remove this import as BufferEncoding
is a global with @types/node
loaded.
630d995
to
0c8134b
Compare
0c8134b
to
42ac066
Compare
620e1ba
to
1095ce6
Compare
410a18a
to
ce393bd
Compare
if (typeof hashedFilePath !== 'string') { | ||
// If no "astro:scripts/before-hydration.js" script exists in the build, | ||
// then we can assume that no before-hydration scripts are needed. | ||
if (specifier === BEFORE_HYDRATION_SCRIPT_ID) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check is the reason that so many hybrid render builds are failing,
in packages/src/core/build/plugins/plugin-manifest.ts:238
you are setting entryModules[BEFORE_HYDRATION_SCRIPT_ID] = ''
, then here you are checking if (typeof hashedFilePath !== 'string')
and inside that check you are checking if (specifier === BEFORE_HYDRATION_SCRIPT_ID)
, but as you have already set the BEFORE_HYDRATION_SCRIPT_ID
in plugin-manifest.ts
so this check is never called.
as a result, while resolving BEFORE_HYDRATION_SCRIPT_ID
in packages/astro/src/runtime/server/hydration.ts:157
we get "/"
instead of ""
, for which this check passes and before-hydration-url
is generated.
if (beforeHydrationUrl.length) {
island.props['before-hydration-url'] = beforeHydrationUrl;
}
So the potential fixes could be to change the function to be
async resolve(specifier: string) {
//const hashedFilePath = manifest.entryModules[specifier];
// EDIT: This one seems to work, all tests also passes
const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
if (typeof hashedFilePath !== 'string') {
// If no "astro:scripts/before-hydration.js" script exists in the build,
// then we can assume that no before-hydration scripts are needed.
if (specifier === BEFORE_HYDRATION_SCRIPT_ID && hashedFilePath === "") {
return '';
}
throw new Error(`Cannot find the built path for ${specifier}`);
}
return createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
},
or change the check at packages/astro/src/runtime/server/hydration.ts:157
to be
// Its more of a workaround than a fix
if (beforeHydrationUrl.length !== 0 && beforeHydrationUrl !== "/") {
island.props['before-hydration-url'] = beforeHydrationUrl;
}
I am down to make a PR to fix the issue (#8379 and many more), just waiting for confrimations from the maintainers
Changes
This PR refactors the build process using the
Pipeline
class.Here's a list of significant changes:
plugin-manifest
plugin to generate the manifest. Themanifest
object is now emitted in a separate file calledmanifest.mjs
. The file is emitted in theconfig.build.server
folder. This is an internal refactoring. I went with this change because the manifest was repeated for each emitted entry/route, giving the impression that a manifest belongs to an entry/route. This isn't correct. A manifest belongs to the whole app. It made more sense to have a separate file with this information.BuildPipeline
class that extendsPipeline
, which is responsible for giving all the essential information to its consumers; for example,BuildInternals
andStaticOuputOptions
are now insideBuildPipeline
and with a series of getters, the consumers retrieve the information needed.Testing
Current tests should pass.
Docs
N/A internal refactor