Skip to content
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

Chore/issue 532 esm upgrade #707

Merged
merged 37 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
66bef6e
WIP
thescientist13 Aug 29, 2021
5c19db0
init upgrade graphql plugin to ESM
thescientist13 Aug 31, 2021
76d95d1
fix linting
thescientist13 Aug 31, 2021
308ffa1
got develop command working for the website
thescientist13 Aug 31, 2021
4382dd1
build command WIP
thescientist13 Aug 31, 2021
785cb9d
migrate node module utils to async and refactor require to import.meta
thescientist13 Oct 26, 2021
3ee7b67
pass linter
thescientist13 Oct 26, 2021
a10b940
remove comment
thescientist13 Oct 27, 2021
cdcab2b
www/ greenwood build command working
thescientist13 Nov 12, 2021
6dc4727
PostCSS working for both develop and build
thescientist13 Nov 13, 2021
56d008a
PostCSS working for both develop and build
thescientist13 Nov 13, 2021
0262a4c
async prodServer support
thescientist13 Nov 13, 2021
0e1db54
fix serve task not resolving standard web assets
thescientist13 Nov 13, 2021
6d51d12
restore plugin analyzer
thescientist13 Nov 17, 2021
5fa4fcb
restore plugin analyzer
thescientist13 Nov 17, 2021
9292633
restore unified markdown functionality
thescientist13 Nov 17, 2021
b638e71
fix missed merge conflict
thescientist13 Nov 17, 2021
c91ace1
restore include HTML plugin
thescientist13 Nov 17, 2021
3f115bf
restore polyfills plugin
thescientist13 Nov 17, 2021
99db076
PostCSS 8 deps upgrades
thescientist13 Nov 22, 2021
97bd80f
CLI build default spec passing via ESM
thescientist13 Nov 22, 2021
7e92a17
migrtate all CLI specs to ESM and enable eject
thescientist13 Nov 23, 2021
dda3375
fix spec
thescientist13 Nov 23, 2021
f926ab4
migrate init package specs to ESM
thescientist13 Nov 23, 2021
77c6126
migrate google and polyfills plugins and specs to ESM
thescientist13 Nov 26, 2021
3fedfbc
migrate plugin-include-html to ESM
thescientist13 Nov 26, 2021
64942d4
migrate plugin import CSS, JSON, and CommonJS and their specs to ESM
thescientist13 Nov 26, 2021
c8b0a73
migrate plugin GraphQL and test cases to ESM
thescientist13 Nov 26, 2021
dbdc82a
migrate plugin GraphQL and unit tests to ESM
thescientist13 Nov 26, 2021
99250d9
migrate plugin typescript and specs to ESM
thescientist13 Nov 26, 2021
a10dfd5
migrate plugin postcss specs to ESM
thescientist13 Nov 26, 2021
60b1d0d
migrate plugin babel and default spec case to ESM
thescientist13 Nov 26, 2021
db3dd8f
update package READMEs for ESM
thescientist13 Nov 29, 2021
557fc94
update docs to demonstrate ESM usage
thescientist13 Nov 29, 2021
64eced6
fix linting
thescientist13 Nov 30, 2021
c4ffb1f
handle path seperator to fix failing spec
thescientist13 Nov 30, 2021
2829f7d
bug/issue 532 esm upgrade with fix for windows (#814)
thescientist13 Dec 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/.greenwood/**
**/public/**
**/node_modules/**
!.eslintrc.js
!.eslintrc.cjs
!.mocharc.js
packages/plugin-babel/test/cases/**/*main.js
File renamed without changes.
File renamed without changes.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ npm install @greenwood/cli --save-dev
yarn add @greenwood/cli --dev
```

Then in your _package.json_, you can run the CLI like so:
```javascript
"scripts": {
"build": "greenwood build",
"start": "greenwood develop",
"serve": "greenwood serve"
Then in your _package.json_, add the `type` field and `scripts` for the CLI, like so:
```json
{
"type": "module",
"scripts": {
"build": "greenwood build",
"start": "greenwood develop",
"serve": "greenwood serve"
}
}
```

Expand Down
32 changes: 16 additions & 16 deletions greenwood.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const path = require('path');
const pluginGraphQL = require('@greenwood/plugin-graphql');
const pluginIncludeHtml = require('@greenwood/plugin-include-html');
const pluginImportCss = require('@greenwood/plugin-import-css');
const pluginImportJson = require('@greenwood/plugin-import-json');
const pluginPolyfills = require('@greenwood/plugin-polyfills');
const pluginPostCss = require('@greenwood/plugin-postcss');
const rollupPluginAnalyzer = require('rollup-plugin-analyzer');
import { greenwoodPluginGraphQL } from '@greenwood/plugin-graphql';
import { greenwoodPluginIncludeHTML } from '@greenwood/plugin-include-html';
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 rollupPluginAnalyzer from 'rollup-plugin-analyzer';
import { fileURLToPath, URL } from 'url';

const META_DESCRIPTION = 'A modern and performant static site generator supporting Web Component based development';
const FAVICON_HREF = '/assets/favicon.ico';

module.exports = {
workspace: path.join(__dirname, 'www'),
export default {
workspace: fileURLToPath(new URL('./www', import.meta.url)),
mode: 'mpa',
optimization: 'inline',
title: 'Greenwood',
Expand All @@ -28,11 +28,11 @@ module.exports = {
{ name: 'google-site-verification', content: '4rYd8k5aFD0jDnN0CCFgUXNe4eakLP4NnA18mNnK5P0' }
],
plugins: [
...pluginGraphQL(),
...pluginPolyfills(),
pluginPostCss(),
...pluginImportJson(),
...pluginImportCss(),
...greenwoodPluginGraphQL(),
...greenwoodPluginPolyfills(),
greenwoodPluginPostCss(),
...greenwoodPluginImportJson(),
...greenwoodPluginImportCss(),
{
type: 'rollup',
name: 'rollup-plugin-analyzer',
Expand All @@ -47,7 +47,7 @@ module.exports = {
];
}
},
...pluginIncludeHtml()
...greenwoodPluginIncludeHTML()
],
markdown: {
plugins: [
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "Owen Buckley <owen@thegreenhouse.io>",
"license": "MIT",
"main": "./packages/cli/src/index.js",
"type": "module",
"workspaces": {
"packages": [
"packages/*",
Expand Down Expand Up @@ -42,7 +43,7 @@
"glob-promise": "^3.4.0",
"jsdom": "^14.0.0",
"lerna": "^3.16.4",
"mocha": "^6.1.4",
"mocha": "^9.1.3",
"nyc": "^14.0.0",
"rimraf": "^2.6.3",
"stylelint": "^13.8.0",
Expand Down
13 changes: 8 additions & 5 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ yarn add @greenwood/cli --dev
```

## Usage
Then in your _package.json_, you can run the CLI like so:
```javascript
"scripts": {
"build": "greenwood build",
"start": "greenwood develop"
Then in your _package.json_, add the `type` field and `scripts` for the CLI like so:
```json
{
"type": "module",
"scripts": {
"build": "greenwood build",
"start": "greenwood develop"
}
}
```

Expand Down
7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@greenwood/cli",
"version": "0.19.3",
"description": "Greenwood CLI.",
"type": "module",
"repository": "https://github.com/ProjectEvergreen/greenwood/tree/master/packages/cli",
"author": "Owen Buckley <owen@thegreenhouse.io>",
"license": "MIT",
Expand Down Expand Up @@ -29,15 +30,15 @@
"acorn": "^8.0.1",
"acorn-walk": "^8.0.0",
"commander": "^2.20.0",
"cssnano": "^4.1.10",
"cssnano": "^5.0.11",
"es-module-shims": "^0.5.2",
"front-matter": "^4.0.2",
"koa": "^2.13.0",
"livereload": "^0.9.1",
"markdown-toc": "^1.2.0",
"node-html-parser": "^1.2.21",
"postcss": "^7.0.32",
"postcss-import": "^12.0.0",
"postcss": "^8.3.11",
"postcss-import": "^13.0.0",
"puppeteer": "^10.2.0",
"rehype-raw": "^5.0.0",
"rehype-stringify": "^8.0.0",
Expand Down
24 changes: 13 additions & 11 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const bundleCompilation = require('../lifecycles/bundle');
const copyAssets = require('../lifecycles/copy');
const { devServer } = require('../lifecycles/serve');
const fs = require('fs');
const generateCompilation = require('../lifecycles/compile');
const { preRenderCompilation, staticRenderCompilation } = require('../lifecycles/prerender');
const { ServerInterface } = require('../lib/server-interface');
import { bundleCompilation } from '../lifecycles/bundle.js';
import { copyAssets } from '../lifecycles/copy.js';
import { devServer } from '../lifecycles/serve.js';
import fs from 'fs';
import { generateCompilation } from '../lifecycles/compile.js';
import { preRenderCompilation, staticRenderCompilation } from '../lifecycles/prerender.js';
import { ServerInterface } from '../lib/server-interface.js';

module.exports = runProductionBuild = async () => {
const runProductionBuild = async () => {

return new Promise(async (resolve, reject) => {

Expand All @@ -21,9 +21,9 @@ module.exports = runProductionBuild = async () => {
}

if (prerender) {
await new Promise((resolve, reject) => {
await new Promise(async (resolve, reject) => {
try {
devServer(compilation).listen(port, async () => {
(await devServer(compilation)).listen(port, async () => {
console.info(`Started local development server at localhost:${port}`);

const servers = [...compilation.config.plugins.filter((plugin) => {
Expand Down Expand Up @@ -65,4 +65,6 @@ module.exports = runProductionBuild = async () => {
}
});

};
};

export { runProductionBuild };
16 changes: 9 additions & 7 deletions packages/cli/src/commands/develop.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const generateCompilation = require('../lifecycles/compile');
const { ServerInterface } = require('../lib/server-interface');
const { devServer } = require('../lifecycles/serve');
import { generateCompilation } from '../lifecycles/compile.js';
import { ServerInterface } from '../lib/server-interface.js';
import { devServer } from '../lifecycles/serve.js';

module.exports = runDevServer = async () => {
const runDevServer = async () => {

return new Promise(async (resolve, reject) => {

try {
const compilation = await generateCompilation();
const { port } = compilation.config.devServer;

devServer(compilation).listen(port, () => {
(await devServer(compilation)).listen(port, () => {

console.info(`Started local development server at localhost:${port}`);

Expand All @@ -27,12 +27,14 @@ module.exports = runDevServer = async () => {
})];

return Promise.all(servers.map(async (server) => {
return server.start();
return await server.start();
}));
});
} catch (err) {
reject(err);
}

});
};
};

export { runDevServer };
22 changes: 13 additions & 9 deletions packages/cli/src/commands/eject.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const fs = require('fs');
const generateCompilation = require('../lifecycles/compile');
const path = require('path');
import fs from 'fs';
import { generateCompilation } from '../lifecycles/compile.js';
import path from 'path';
import { fileURLToPath, URL } from 'url';

module.exports = ejectConfiguration = async () => {
const ejectConfiguration = async () => {
return new Promise(async (resolve, reject) => {
try {
const compilation = await generateCompilation();
const configFilePaths = fs.readdirSync(path.join(__dirname, '../config'));

configFilePaths.forEach((configFile) => {
const from = path.join(__dirname, '../config', configFile);
const configFilePath = fileURLToPath(new URL('../config', import.meta.url));
const configFiles = fs.readdirSync(configFilePath);

configFiles.forEach((configFile) => {
const from = path.join(configFilePath, configFile);
const to = `${compilation.context.projectDirectory}/${configFile}`;

fs.copyFileSync(from, to);
Expand All @@ -24,4 +26,6 @@ module.exports = ejectConfiguration = async () => {
reject(err);
}
});
};
};

export { ejectConfiguration };
12 changes: 7 additions & 5 deletions packages/cli/src/commands/serve.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const generateCompilation = require('../lifecycles/compile');
const { prodServer } = require('../lifecycles/serve');
import { generateCompilation } from '../lifecycles/compile.js';
import { prodServer } from '../lifecycles/serve.js';

module.exports = runProdServer = async () => {
const runProdServer = async () => {

return new Promise(async (resolve, reject) => {

try {
const compilation = await generateCompilation();
const port = 8080;

prodServer(compilation).listen(port, () => {
(await prodServer(compilation)).listen(port, () => {
console.info(`Started production test server at localhost:${port}`);
});
} catch (err) {
reject(err);
}

});
};
};

export { runProdServer };
17 changes: 10 additions & 7 deletions packages/cli/src/config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable max-depth, no-loop-func */
const fs = require('fs');
const htmlparser = require('node-html-parser');
const path = require('path');
const postcss = require('postcss');
const postcssImport = require('postcss-import');
import fs from 'fs';
import htmlparser from 'node-html-parser';
import path from 'path';
import postcss from 'postcss';
import postcssImport from 'postcss-import';

const tokenSuffix = 'scratch';
const tokenNodeModules = 'node_modules';

Expand Down Expand Up @@ -506,7 +507,7 @@ function greenwoodHtmlPlugin(compilation) {
};
}

module.exports = getRollupConfig = async (compilation) => {
const getRollupConfig = async (compilation) => {
const { scratchDir, outputDir } = compilation.context;
const inputs = compilation.graph.map((page) => {
return path.normalize(`${scratchDir}${page.outputPath}`);
Expand Down Expand Up @@ -570,4 +571,6 @@ module.exports = getRollupConfig = async (compilation) => {
]
}];

};
};

export { getRollupConfig };
15 changes: 9 additions & 6 deletions packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
// https://github.com/ProjectEvergreen/greenwood/issues/141
process.setMaxListeners(0);

const program = require('commander');
const runProductionBuild = require('./commands/build');
const runDevServer = require('./commands/develop');
const runProdServer = require('./commands/serve');
const ejectConfiguration = require('./commands/eject');
const greenwoodPackageJson = require('../package.json');
import program from 'commander';
import fs from 'fs/promises';
import { URL } from 'url';

import { runDevServer } from './commands/develop.js';
import { runProductionBuild } from './commands/build.js';
import { runProdServer } from './commands/serve.js';
import { ejectConfiguration } from './commands/eject.js';

const greenwoodPackageJson = JSON.parse(await fs.readFile(new URL('../package.json', import.meta.url), 'utf-8'));
let cmdOption = {};
let command = '';

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Wraps Puppeteer's interface to Headless Chrome to expose high level rendering
* APIs that are able to handle web components and PWAs.
*/
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

class BrowserRunner {

Expand Down Expand Up @@ -84,4 +84,4 @@ class BrowserRunner {
}
}

module.exports = BrowserRunner;
export { BrowserRunner };
Loading