Skip to content

Commit

Permalink
latest WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Nov 1, 2022
1 parent 4ceb75b commit a640af1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
6 changes: 3 additions & 3 deletions greenwood.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { greenwoodPluginImportCss } from '@greenwood/plugin-import-css';
import { greenwoodPluginImportJson } from '@greenwood/plugin-import-json';
import { greenwoodPluginPolyfills } from '@greenwood/plugin-polyfills';
import { greenwoodPluginPostCss } from '@greenwood/plugin-postcss';
// import { greenwoodPluginRendererPuppeteer } from '@greenwood/plugin-renderer-puppeteer';
import { greenwoodPluginRendererPuppeteer } from '@greenwood/plugin-renderer-puppeteer';
import rollupPluginAnalyzer from 'rollup-plugin-analyzer';
import { fileURLToPath, URL } from 'url';

Expand Down Expand Up @@ -34,8 +34,8 @@ export default {
];
}
},
greenwoodPluginIncludeHTML()
// greenwoodPluginRendererPuppeteer() // can only have one renderer at a time
greenwoodPluginIncludeHTML(),
greenwoodPluginRendererPuppeteer()
],
markdown: {
plugins: [
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"lerna": "lerna",
"clean": "rimraf ./**/.greenwood/** && rimraf ./**/public/** && rimraf ./coverage",
"clean:deps": "rimraf **/node_modules/**",
"build": "cross-env __GWD_ROLLUP_MODE__=strict node --experimental-loader ./node_modules/@greenwood/cli/src/loader.js . build",
"serve": "node --experimental-loader ./node_modules/@greenwood/cli/src/loader.js . serve",
"develop": "node --experimental-loader ./node_modules/@greenwood/cli/src/loader.js . develop",
"build": "cross-env __GWD_ROLLUP_MODE__=strict node --experimental-loader ./packages/cli/src/loader.js . build",
"serve": "node --experimental-loader ./packages/cli/src/loader.js . serve",
"develop": "node --experimental-loader ./packages/cli/src/loader.js . develop",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict c8 mocha",
"test:tdd": "yarn test --watch",
"lint:js": "eslint \"*.js\" \"./packages/**/**/*.js\" \"./test/*.js\" \"./www/**/**/*.js\"",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ function greenwoodResourceLoader (compilation) {
const extension = path.extname(importAsIdAsUrl);

if (extension !== '.js') {
const originalUrl = `${id}?type=${extension.replace('.', '')}`;
let contents;

for (const plugin of resourcePlugins) {
const headers = {
request: {
originalUrl: id
originalUrl
},
response: {
'content-type': plugin.contentType
Expand Down
9 changes: 0 additions & 9 deletions packages/cli/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@ function getCustomLoaderPlugins(url, body, headers) {

export function resolve(specifier, context, defaultResolve) {
const { parentURL = baseURL } = context;
console.debug('RESOLVE', specifier);

if (getCustomLoaderPlugins(specifier).length > 0) {
console.debug('===> use custom resolve', new URL(specifier, parentURL).href);
return {
url: new URL(specifier, parentURL).href
};
}

console.debug('===> use default resolve');
return defaultResolve(specifier, context, defaultResolve);
}

export async function load(source, context, defaultLoad) {
console.debug('###### LOAD');
const resourcePlugins = getCustomLoaderPlugins(source);

if (resourcePlugins.length) {
console.debug('===> use custom load', source);
const headers = {
request: {
originalUrl: `${source}?type=${path.extname(source).replace('.', '')}`,
Expand All @@ -45,27 +40,23 @@ export async function load(source, context, defaultLoad) {
};
let contents = '';

console.debug('111111', contents);
for (const plugin of resourcePlugins) {
if (await plugin.shouldServe(source, headers)) {
contents = (await plugin.serve(source, headers)).body || contents;
}
}

console.debug('222222', contents);
for (const plugin of resourcePlugins) {
if (await plugin.shouldIntercept(fileURLToPath(source), contents, headers)) {
contents = (await plugin.intercept(fileURLToPath(source), contents, headers)).body || contents;
}
}

console.debug('@@@@@@@@@', { contents });
return {
format: 'module',
source: contents
};
}

console.debug('===> use default load', source);
return defaultLoad(source, context, defaultLoad);
}

0 comments on commit a640af1

Please sign in to comment.