Skip to content

Commit

Permalink
it works
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Sep 7, 2023
1 parent 0552e19 commit e224226
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 28 deletions.
48 changes: 24 additions & 24 deletions patches/@greenwood+cli+0.29.0-alpha.3.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/@greenwood/cli/src/config/rollup.config.js b/node_modules/@greenwood/cli/src/config/rollup.config.js
index df59ef6..9eedbc8 100644
index df59ef6..5ea6ef5 100644
--- a/node_modules/@greenwood/cli/src/config/rollup.config.js
+++ b/node_modules/@greenwood/cli/src/config/rollup.config.js
@@ -10,10 +10,14 @@ function greenwoodJsonLoader() {
Expand Down Expand Up @@ -37,29 +37,42 @@ index df59ef6..9eedbc8 100644
const { outputDir } = compilation.context;
const input = [...compilation.resources.values()]
.filter(resource => resource.type === 'script')
@@ -212,9 +218,15 @@ const getRollupConfigForScriptResources = async (compilation) => {
@@ -212,10 +218,20 @@ const getRollupConfigForScriptResources = async (compilation) => {
};

const getRollupConfigForApis = async (compilation) => {
+ console.log('##### getRollupConfigForApis');
const { outputDir, userWorkspace } = compilation.context;
const input = [...compilation.manifest.apis.values()]
.map(api => normalizePathnameForWindows(new URL(`.${api.path}`, userWorkspace)));
-
+ const customRollupPlugins = compilation.config.plugins.filter(plugin => {
+ return plugin.type === 'rollup';
+ }).map(plugin => {
+ return plugin.provider(compilation);
+ }).flat();

+
+ // TODO why is this needed?
+ await fs.mkdir(new URL('./api/assets/', outputDir), {
+ recursive: true
+ });
// TODO should routes and APIs have chunks?
// https://github.com/ProjectEvergreen/greenwood/issues/1118
@@ -229,13 +241,22 @@ const getRollupConfigForApis = async (compilation) => {
return [{
@@ -225,17 +241,29 @@ const getRollupConfigForApis = async (compilation) => {
entryFileNames: '[name].js',
chunkFileNames: '[name].[hash].js'
},
+ // TODO should these plugins match across all configurations?
+ // TODO sync with SSR config
plugins: [
greenwoodJsonLoader(),
+ greenwoodResourceLoader(compilation),
nodeResolve(),
commonjs(),
- importMetaAssets()
+ importMetaAssets(),
+ ...customRollupPlugins,
+ // TODO ??? ...customRollupPlugins,
]
}];
};
Expand All @@ -77,41 +90,28 @@ index df59ef6..9eedbc8 100644

// TODO should routes and APIs have chunks?
// https://github.com/ProjectEvergreen/greenwood/issues/1118
@@ -248,6 +269,7 @@ const getRollupConfigForSsr = async (compilation, input) => {
@@ -248,6 +276,7 @@ const getRollupConfigForSsr = async (compilation, input) => {
},
plugins: [
greenwoodJsonLoader(),
+ greenwoodResourceLoader(compilation),
// TODO let this through for lit to enable nodeResolve({ preferBuiltins: true })
// https://github.com/lit/lit/issues/449
// https://github.com/ProjectEvergreen/greenwood/issues/1118
@@ -255,7 +277,11 @@ const getRollupConfigForSsr = async (compilation, input) => {
preferBuiltins: true
}),
commonjs(),
- importMetaAssets(),
+ importMetaAssets({
+ // include: ['*.js'],
+ // exclude: ['*.css', '*.json'],
+ }),
+ // ...customRollupPlugins,
greenwoodPatchSsrPagesEntryPointRuntimeImport() // TODO a little hacky but works for now
],
onwarn: (errorObj) => {
diff --git a/node_modules/@greenwood/cli/src/loader.js b/node_modules/@greenwood/cli/src/loader.js
index 7955b24..856902e 100644
index 7955b24..964ab71 100644
--- a/node_modules/@greenwood/cli/src/loader.js
+++ b/node_modules/@greenwood/cli/src/loader.js
@@ -46,7 +46,12 @@ async function getCustomLoaderResponse(url, body = '', checkOnly = false) {
// https://nodejs.org/docs/latest-v18.x/api/esm.html#resolvespecifier-context-nextresolve
export async function resolve(specifier, context, defaultResolve) {
const { parentURL } = context;
- const { shouldHandle } = await getCustomLoaderResponse(new URL(specifier), null, true);
+ console.log({ specifier, context, parentURL })
+ // console.log({ specifier, context, parentURL })
+ const x = specifier.startsWith('file://')
+ ? new URL(specifier)
+ : new URL(specifier, parentURL);
+ console.log({ x });
+ // console.log({ x });
+ const { shouldHandle } = await getCustomLoaderResponse(x, null, true);

if (shouldHandle) {
Expand All @@ -123,7 +123,7 @@ index 7955b24..856902e 100644
- const extension = source.split('.').pop();
- const url = new URL('', `${source}?type=${extension}`);
- const { shouldHandle } = await getCustomLoaderResponse(url, null, true);
+ console.log('LOAD', { source, context });
+ // console.log('LOAD', { source, context });
+ if (source.startsWith('file://')) {
+ const extension = source.split('.').pop();
+ const url = new URL(`${source}?type=${extension}`);
Expand All @@ -133,7 +133,7 @@ index 7955b24..856902e 100644
- const contents = await fs.readFile(new URL(source), 'utf-8');
- const { response } = await getCustomLoaderResponse(url, contents);
- const body = await response.text();
+ console.log('should handle?????', shouldHandle);
+ // console.log('should handle?????', shouldHandle);
+ if (shouldHandle) {
+ const contents = await fs.readFile(new URL(source), 'utf-8');
+ const { response } = await getCustomLoaderResponse(url, contents);
Expand Down
47 changes: 43 additions & 4 deletions patches/@web+rollup-plugin-import-meta-assets+1.0.8.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
diff --git a/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js b/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js
index 1d0280c..f4aeb21 100644
index 1d0280c..1d2e461 100644
--- a/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js
+++ b/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js
@@ -58,10 +58,14 @@ function importMetaAssets({ include, exclude, warnOnError, transform } = {}) {
@@ -58,10 +58,13 @@ function importMetaAssets({ include, exclude, warnOnError, transform } = {}) {
name: 'rollup-plugin-import-meta-assets',

async transform(code, id) {
+ console.log({ id });
if (!filter(id)) {
+ console.log('NULL @@@@@', { code });
return null;
}

+ console.log('here!?!!?!?!');
+ console.log('here!?!!?!?!', { id });
+
const ast = this.parse(code);
const magicString = new MagicString(code);
let modifiedCode = false;
@@ -74,6 +77,7 @@ function importMetaAssets({ include, exclude, warnOnError, transform } = {}) {
const absoluteAssetPath = path.resolve(absoluteScriptDir, relativeAssetPath);
const assetName = path.basename(absoluteAssetPath);

+ console.log({ absoluteAssetPath, absoluteScriptDir, relativeAssetPath });
try {
const assetContents = await fs.promises.readFile(absoluteAssetPath);
const transformedAssetContents =
@@ -83,11 +87,20 @@ function importMetaAssets({ include, exclude, warnOnError, transform } = {}) {
if (transformedAssetContents === null) {
return;
}
+ // https://github.com/rollup/rollup/blob/v2.79.1/docs/05-plugin-development.md#thisemitfile
const ref = this.emitFile({
- type: 'asset',
+ type: 'chunk',
+ id: absoluteAssetPath,
+ // preserveSignature: 'strict'
name: assetName,
- source: transformedAssetContents,
+ // source: transformedAssetContents,
});
+ // const ref = this.emitFile({
+ // type: 'asset',
+ // name: assetName,
+ // source: transformedAssetContents,
+ // });
+ console.log({ ref });
magicString.overwrite(
node.arguments[0].start,
node.arguments[0].end,
@@ -105,6 +118,8 @@ function importMetaAssets({ include, exclude, warnOnError, transform } = {}) {
},
});

+ console.log('(((((((((((((((((');
+
return {
code: magicString.toString(),
map: modifiedCode ? magicString.generateMap({ hires: true }) : null,

0 comments on commit e224226

Please sign in to comment.