-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/issue 878 ssr custom resources (#992)
* Enhancement/issue 971 refactor bundling and optimizations (#974) * add cloud IDE caveat to puppeteer renderer plugin readme (#967) * init commit of refactoring for script tags with a src * initial CSS optimizing * sync optimized link tags in final output * refactored for shared reources * handle inline script bundling * support serving custom resources using Greenwood plugins in Rollup configuration without needing extra rollup plugin * non resource related Rollup plugins supported * custom resource plugins and rollup plugins working together * handle empty input for Rollup * updated lock file * handle inline style tag bundling and optimizing * default optimization spec passing * refactor merging app and page templates * clarifying corrections in spec files * inline optimization config working * none optimization support * none optimization support * none and static optimization overrides * refactor html rendering and optimizing * refactoring and more CLI specs passing * add missing variable * SSR specs and optimizing resource bundling * minor refactoring and logging * resolving some plugin specs * restore develop command related GraphQL specs * custom graphql query spec * all specs passing * drop rollup plugin deps from import typescript plugin * all Greenwood commands and specs passing * restore static router with custom prerender * restore postcss-import * refactor shared resources to a Map and handle dupes * restore local packages workaround for local Rollup bundling * better monorepo Rollup facade modules detection * switch console log * remove console logging * update plugin related docs * local solution for windows support * refactor errant object assign * full cross platform URL support * fix lint * fix extra bundles when custom prerendering * clean up stale or already tracked TODOs * add nested head tag smoke tests * check for app template validation for HUD display * misc refactoring and TODOs cleanup * restore static router (again) * standardize passing correct reference for prerender scripts * clean up data-gwd-opt markers from final HTML * v0.27.0-alpha.0 * experimental loaders for SSR custom resources * set minimum nodejs v16.x requirement * latest WIP * custom SSR loaders for JSON * working test case testing for SSR prerender with import CSS plugin * experimental test task and github actions * remove demo code * add test cases for import JSON with prerendering * upgrade latest gallinago * enable experimental testing capabilities for CI * post rebase reconsilations * align versioning * experimental specs passing on windows * remove lint from experimental github actions * refine exp test tasks * minor refactor * fix windows exp github action workflow * increase mocha timeout for to accomodate exp test runs * formatting * updated import CSS and JSON plugin README docs * SSR usage for experimental loaders
- Loading branch information
1 parent
4f627bc
commit 04e25c4
Showing
28 changed files
with
519 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Continuous Integration (Experimental) | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-18.04 | ||
|
||
strategy: | ||
matrix: | ||
node: [16] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Install Chromium Library Dependencies | ||
run: | | ||
sh ./.github/workflows/chromium-lib-install.sh | ||
- name: Use Node.js ${{ matrix.node }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Installing project dependencies | ||
run: | | ||
yarn install --frozen-lockfile && yarn lerna bootstrap | ||
- name: Test | ||
run: | | ||
yarn test:exp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Continuous Integration Windows (Experimental) | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: windows-latest | ||
|
||
strategy: | ||
matrix: | ||
node: [16] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Installing project dependencies | ||
run: | | ||
yarn install --frozen-lockfile --network-timeout 1000000 && yarn lerna bootstrap | ||
- name: Test | ||
run: | | ||
yarn test:exp:win |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
spec: path.join(__dirname, 'packages/**/test/**/**/**/*.spec.js'), | ||
timeout: 60000 | ||
timeout: 90000 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
14.17.0 | ||
16.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Node ^16.17.0 | ||
import path from 'path'; | ||
import { readAndMergeConfig as initConfig } from './lifecycles/config.js'; | ||
import { URL, fileURLToPath } from 'url'; | ||
|
||
const config = await initConfig(); | ||
const plugins = config.plugins.filter(plugin => plugin.type === 'resource' && !plugin.isGreenwoodDefaultPlugin).map(plugin => plugin.provider({ | ||
context: { | ||
projectDirectory: process.cwd() | ||
} | ||
})); | ||
|
||
// TODO need to polyfill original URL header instead of extensions? | ||
function getCustomLoaderPlugins(url, body, headers) { | ||
return plugins.filter(plugin => plugin.extensions.includes(path.extname(url)) && (plugin.shouldServe(url, body, headers) || plugin.shouldIntercept(url, body, headers))); | ||
} | ||
|
||
// https://nodejs.org/docs/latest-v16.x/api/esm.html#resolvespecifier-context-nextresolve | ||
export function resolve(specifier, context, defaultResolve) { | ||
const { baseURL } = context; | ||
|
||
if (getCustomLoaderPlugins(specifier).length > 0) { | ||
return { | ||
url: new URL(specifier, baseURL).href, | ||
shortCircuit: true | ||
}; | ||
} | ||
|
||
return defaultResolve(specifier, context, defaultResolve); | ||
} | ||
|
||
// https://nodejs.org/docs/latest-v16.x/api/esm.html#loadurl-context-nextload | ||
export async function load(source, context, defaultLoad) { | ||
const resourcePlugins = getCustomLoaderPlugins(source); | ||
const extension = path.extname(source).replace('.', ''); | ||
|
||
if (resourcePlugins.length) { | ||
const headers = { | ||
request: { | ||
originalUrl: `${source}?type=${extension}`, | ||
accept: '' | ||
} | ||
}; | ||
let contents = ''; | ||
|
||
for (const plugin of resourcePlugins) { | ||
if (await plugin.shouldServe(source, headers)) { | ||
contents = (await plugin.serve(source, headers)).body || contents; | ||
} | ||
} | ||
|
||
for (const plugin of resourcePlugins) { | ||
if (await plugin.shouldIntercept(fileURLToPath(source), contents, headers)) { | ||
contents = (await plugin.intercept(fileURLToPath(source), contents, headers)).body || contents; | ||
} | ||
} | ||
|
||
// TODO better way to handle remove export default? | ||
// https://github.com/ProjectEvergreen/greenwood/issues/948 | ||
return { | ||
format: extension === 'json' ? 'json' : 'module', | ||
source: extension === 'json' ? JSON.parse(contents.replace('export default ', '')) : contents, | ||
shortCircuit: true | ||
}; | ||
} | ||
|
||
return defaultLoad(source, context, defaultLoad); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/plugin-import-css/test/cases/exp-build.prerender/exp-build.prerender.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood with pluginImportCss plugin with prerendering of CSS on the server side. | ||
* | ||
* User Result | ||
* Should generate a static Greenwood build with CSS properly prerendered. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* import { greenwoodPluginImportCss } from '@greenwood/plugin-import-css'; | ||
* | ||
* { | ||
* plugins: [{ | ||
* greenwoodPluginImportCss() | ||
* }] | ||
* } | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* footer.css | ||
* footer.js | ||
* pages/ | ||
* index.md | ||
* templates/ | ||
* app.html | ||
*/ | ||
import chai from 'chai'; | ||
import glob from 'glob-promise'; | ||
import { JSDOM } from 'jsdom'; | ||
import path from 'path'; | ||
import { runSmokeTest } from '../../../../../test/smoke-test.js'; | ||
import { getSetupFiles, getOutputTeardownFiles } from '../../../../../test/utils.js'; | ||
import { Runner } from 'gallinago'; | ||
import { fileURLToPath, URL } from 'url'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('(Experimental) Build Greenwood With: ', function() { | ||
const LABEL = 'Import CSS Plugin with static pre-rendering'; | ||
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js'); | ||
const outputPath = fileURLToPath(new URL('.', import.meta.url)); | ||
let runner; | ||
|
||
before(async function() { | ||
this.context = { | ||
publicDir: path.join(outputPath, 'public') | ||
}; | ||
runner = new Runner(false, true); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
before(async function() { | ||
await runner.setup(outputPath, getSetupFiles(outputPath)); | ||
await runner.runCommand(cliPath, 'build'); | ||
}); | ||
|
||
runSmokeTest(['public'], LABEL); | ||
|
||
describe('importing CSS using ESM (import)', function() { | ||
let dom; | ||
let scripts; | ||
|
||
before(async function() { | ||
scripts = await glob.promise(path.join(this.context.publicDir, '*.js')); | ||
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, './index.html')); | ||
}); | ||
|
||
it('should contain no (CSS-in) JavaScript file in the output directory', function() { | ||
expect(scripts.length).to.be.equal(0); | ||
}); | ||
|
||
it('should have the expected output from importing styles.css in index.html', function() { | ||
const styles = dom.window.document.querySelectorAll('style'); | ||
|
||
// TODO minify CSS-in-JS? | ||
expect(styles.length).to.equal(1); | ||
expect(styles[0].textContent).to.contain('.footer { width: 90%; margin: 0 auto; padding: 0; text-align: center; }'); | ||
}); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
runner.teardown(getOutputTeardownFiles(outputPath)); | ||
}); | ||
|
||
}); |
8 changes: 8 additions & 0 deletions
8
packages/plugin-import-css/test/cases/exp-build.prerender/greenwood.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { greenwoodPluginImportCss } from '../../../src/index.js'; | ||
|
||
export default { | ||
prerender: true, | ||
plugins: [ | ||
...greenwoodPluginImportCss() | ||
] | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/plugin-import-css/test/cases/exp-build.prerender/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test-plugin-import-css-build-prerender", | ||
"type": "module" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/plugin-import-css/test/cases/exp-build.prerender/src/components/footer.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.footer { width: 90%; margin: 0 auto; padding: 0; text-align: center; } |
Oops, something went wrong.