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

More Preact X compat things™ #756

Merged
merged 8 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.13.0",
"eslint": "^5.15.1",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.7.0",
"husky": "^1.3.1",
"lerna": "^3.13.1",
"lint-staged": "^8.1.3",
"lint-staged": "^8.1.5",
"prettier": "^1.16.4"
},
"husky": {
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/lib/lib/webpack/run-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ async function prodBuild(env) {
function runCompiler(compiler) {
return new Promise((res, rej) => {
compiler.run((err, stats) => {
if (stats && stats.hasErrors()) {
showStats(stats);
}
showStats(stats);

if (err || (stats && stats.hasErrors())) {
rej(red('Build failed! ' + err));
rej(red('Build failed! ' + (err || '')));
}

res(stats);
Expand Down
35 changes: 18 additions & 17 deletions packages/cli/lib/lib/webpack/webpack-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ function readJson(file) {
}

// attempt to resolve a dependency, giving $CWD/node_modules priority:
function resolveDep(dep, cwd) {
try {
return requireRelative.resolve(dep, cwd || process.cwd());
} catch (e) {}
try {
return require.resolve(dep);
} catch (e) {}
return dep;
}
// function resolveDep(dep, cwd) {
// try {
// return requireRelative.resolve(dep, cwd || process.cwd());
// } catch (e) {}
// try {
// return require.resolve(dep);
// } catch (e) {}
// return dep;
// }

function findAllNodeModules(startDir) {
let dir = path.resolve(startDir);
Expand Down Expand Up @@ -61,11 +61,17 @@ module.exports = function(env) {
let cliNodeModules = findAllNodeModules(__dirname);
let nodeModules = [...new Set([...userNodeModules, ...cliNodeModules])];

let compat = 'preact-compat';
try {
requireRelative.resolve('preact/compat', cwd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be trying to resolve this only to node_modules/preact/compat? I think this will resolve to node_modules/preact/compat/dist/compat.js.

compat = 'preact/compat';
} catch (e) {}

return {
context: src,

resolve: {
modules: ['node_modules', ...nodeModules],
modules: [...nodeModules, 'node_modules'],
extensions: [
'.mjs',
'.js',
Expand All @@ -82,14 +88,9 @@ module.exports = function(env) {
alias: {
style: source('style'),
'preact-cli-entrypoint': source('index.js'),
preact$: resolveDep(
isProd ? 'preact/dist/preact.min.js' : 'preact',
cwd
),
// preact-compat aliases for supporting React dependencies:
react: 'preact-compat',
'react-dom': 'preact-compat',
'create-react-class': 'preact-compat/lib/create-react-class',
react: compat,
'react-dom': compat,
'react-addons-css-transition-group': 'preact-css-transition-group',
'preact-cli/async-component': require.resolve(
'@preact/async-loader/async'
Expand Down
47 changes: 28 additions & 19 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
],
"testEnvironment": "node",
"testPathIgnorePatterns": [
"tests/output"
"<rootDir>/tests/output",
"<rootDir>/tests/subjects"
],
"modulePathIgnorePatterns": [
"<rootDir>/tests/output",
"<rootDir>/tests/subjects"
]
},
"engines": {
Expand All @@ -40,19 +45,26 @@
"bugs": "https://github.com/developit/preact-cli/issues",
"homepage": "https://github.com/developit/preact-cli",
"devDependencies": {
"eslint": "^5.14.1",
"eslint": "^5.15.1",
"html-looks-like": "^1.0.2",
"jest": "^24.1.0",
"jest": "^24.5.0",
"lerna": "^3.13.1",
"lint-staged": "^8.1.4",
"lint-staged": "^8.1.5",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"node-sass": "^4.9.0",
"p-retry": "^3.0.1",
"p-retry": "^4.0.0",
"preact": "^8.1.0",
"preact-compat": "^3.14.3",
"preact-render-to-string": "^4.1.0",
"preact-router": "^2.6.1",
"puppeteer": "^1.3.0",
"puppeteer": "^1.13.0",
"sass-loader": "^7.0.1"
},
"peerDependencies": {
"preact": "*",
"preact-render-to-string": "*"
},
"dependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
Expand All @@ -64,21 +76,21 @@
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.3.4",
"@preact/async-loader": "^3.0.0-next.16",
"autoprefixer": "^9.4.9",
"autoprefixer": "^9.4.10",
"babel-esm-plugin": "^0.4.0",
"babel-loader": "^8.0.5",
"babel-plugin-macros": "^2.4.5",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"console-clear": "^1.0.0",
"copy-webpack-plugin": "^5.0.0",
"copy-webpack-plugin": "^5.0.1",
"critters-webpack-plugin": "^1.3.3",
"cross-spawn-promise": "^0.10.1",
"css-loader": "^2.1.0",
"css-loader": "^2.1.1",
"ejs-loader": "^0.3.0",
"esm": "^3.2.7",
"esm": "<=3.2.14",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esm v3.2.17 is released 🎉

"fast-async": "^6.3.7",
"file-loader": "^3.0.1",
"get-port": "^4.1.0",
"get-port": "^4.2.0",
"gittar": "^0.1.0",
"glob": "^7.1.3",
"html-webpack-exclude-assets-plugin": "0.0.7",
Expand All @@ -90,16 +102,13 @@
"mini-css-extract-plugin": "^0.5.0",
"minimatch": "^3.0.3",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"ora": "^3.0.0",
"ora": "^3.2.0",
"postcss-loader": "^3.0.0",
"preact": "^8.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this break prerendering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't, as a peerDep it should resolve fine

"preact-compat": "^3.14.3",
"preact-render-to-string": "^4.1.0",
"progress-bar-webpack-plugin": "^1.12.1",
"promise-polyfill": "^8.1.0",
"prompts": "^2.0.3",
"raw-loader": "^1.0.0",
"react-hot-loader": "^4.7.1",
"react-hot-loader": "^4.8.0",
"require-relative": "^0.8.7",
"rimraf": "^2.6.1",
"sade": "^1.4.1",
Expand All @@ -111,10 +120,10 @@
"update-notifier": "^2.5.0",
"url-loader": "^1.0.1",
"validate-npm-package-name": "^3.0.0",
"webpack": "^4.29.5",
"webpack-bundle-analyzer": "^3.0.4",
"webpack": "^4.29.6",
"webpack-bundle-analyzer": "^3.1.0",
"webpack-dev-server": "^3.2.1",
"webpack-fix-style-only-entries": "^0.2.0",
"webpack-fix-style-only-entries": "^0.2.1",
"webpack-merge": "^4.1.0",
"webpack-plugin-replace": "^1.2.0",
"which": "^1.2.14"
Expand Down
Loading