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

EDIT-938: Upgrade Project Watchtower to Node 18 #101

Merged
merged 49 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a456ba6
Updated parent package to utilise node 18
DownUndaDev Jun 4, 2024
f83867e
Updated typescript version
DownUndaDev Jun 4, 2024
fdab944
Updated jest & ts-jest
DownUndaDev Jun 4, 2024
ed4a2ed
Updated tslib
DownUndaDev Jun 4, 2024
94b4fc7
Updated webpack version
DownUndaDev Jun 4, 2024
1fde0e8
Fixed simple syntax errors
DownUndaDev Jun 4, 2024
7bb275a
Updated example bundle dependency version for webpack
DownUndaDev Jun 4, 2024
2ef4d67
Updated node-sass version to 8.0.0 to match the node version
DownUndaDev Jun 5, 2024
c2035c5
Cleaned up ssr-with-sass to compile successfully
DownUndaDev Jun 5, 2024
f7cdafd
Updated to a generalised webpack version across the board
DownUndaDev Jun 5, 2024
cc7073c
Updated webpack dependencies
DownUndaDev Jun 5, 2024
36687ca
More dependency updates to match webpack5
DownUndaDev Jun 5, 2024
8e7374a
Updated ESLint version and other dependencies to match Webpack5
DownUndaDev Jun 5, 2024
dd79ce0
Added webpack as a dependency to the project
DownUndaDev Jun 5, 2024
9aeaa12
Updated all dependencies to bring cli/server/workspace up to webpack5
DownUndaDev Jun 5, 2024
227cd0b
Fixed up some type errors stopping the project from compiling correctly
DownUndaDev Jun 5, 2024
e7e77b4
Fixed up a few type errors on the test module
DownUndaDev Jun 5, 2024
eb77c6a
Updated html-webpack-plugin to match webpack5
DownUndaDev Jun 5, 2024
10e8d35
Updated snapshot to match new webpack5
DownUndaDev Jun 5, 2024
77f8fa6
Added eslint to disable-next-line on the config.js
DownUndaDev Jun 5, 2024
d659dad
Updated to utilise Node 18 for the GitHub workflow
DownUndaDev Jun 5, 2024
4ff5212
Updated json.json config to remove deprecated ts-json config format
DownUndaDev Jun 5, 2024
c179172
Updated to use node 18 on Setup Node.js
DownUndaDev Jun 5, 2024
b1aa984
Removed unnecessary comments
DownUndaDev Jun 6, 2024
0061298
Updated the project version & added a changeset
DownUndaDev Jun 6, 2024
eb6c621
Fixed up comment with no-undef in the config.js for ssr-with-sass
DownUndaDev Jun 6, 2024
481e8d1
Updated loadable versions to match webpack5
DownUndaDev Jun 6, 2024
56cd872
Upgraded babel version to match webpack5 & Node18
DownUndaDev Jun 6, 2024
f606bbf
Updated esbuild-loader to the latest version
DownUndaDev Jun 6, 2024
4e7642b
Updated react-helmet-async versions
DownUndaDev Jun 6, 2024
5512371
Updated content to utilise new versions of react-helmet-async
DownUndaDev Jun 6, 2024
637affc
Hacky way to fix appRender
DownUndaDev Jun 6, 2024
fb66516
Revert "Hacky way to fix appRender"
DownUndaDev Jun 6, 2024
86e54eb
Revert "Updated react-helmet-async versions"
DownUndaDev Jun 6, 2024
eedb990
Revert "Updated content to utilise new versions of react-helmet-async"
DownUndaDev Jun 6, 2024
99a6a75
Revert "Updated esbuild-loader to the latest version"
DownUndaDev Jun 6, 2024
bb39e39
Revert "Upgraded babel version to match webpack5 & Node18"
DownUndaDev Jun 6, 2024
dca3a50
Revert "Updated loadable versions to match webpack5"
DownUndaDev Jun 6, 2024
c19363c
Applied changes requested by @bennettp123
DownUndaDev Jun 6, 2024
2616141
Fixed issues with the implementation of the css-minimizer-webpack-plugin
DownUndaDev Jun 6, 2024
2cef847
Updated loadable versions and babel versions
DownUndaDev Jun 6, 2024
ae8123e
Fixed issues with client-only package not booting up in Node 18
DownUndaDev Jun 6, 2024
8f046f0
Removed all comments from all tsconfig.json files to stop them from n…
DownUndaDev Jun 6, 2024
6040047
Updated to directly add the util package in support of Webpack5, and …
DownUndaDev Jun 6, 2024
682dc6d
Continued to fix up some commands to run on Node 18
DownUndaDev Jun 6, 2024
a401ca0
Updated postcss, sass-loader & implemented a url fallback for webpack…
DownUndaDev Jun 6, 2024
16795a8
Removed file-loader and utilised webpack5's asset modules on advice o…
DownUndaDev Jun 7, 2024
5a4eff4
Deleted changeset to re-create a new one
DownUndaDev Jun 7, 2024
27c011b
Added new changeset
DownUndaDev Jun 7, 2024
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
9 changes: 9 additions & 0 deletions .changeset/grumpy-bikes-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'bundle-splitting-using-loadable': major
'ssr-with-sass': major
'@project-watchtower/cli': major
'@project-watchtower/server': major
---

Updated packages to use Node 18, Webpack 5 & TSLib 2.6.2.
Your project will need to be running these 3 updated versions in order to accept the latest project-watchtower version.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
steps:
- uses: actions/checkout@master

- name: Set Node.js 10.x
- name: Set Node.js 18
uses: actions/setup-node@master
with:
node-version: 10.x
node-version: '18'

- name: yarn install
run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@master

- name: Setup Node.js 10.x
- name: Setup Node.js 18
uses: actions/setup-node@master
with:
node-version: 10.x
node-version: '18'

DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
- name: Install Dependencies
run: yarn
Expand Down
2 changes: 1 addition & 1 deletion examples/bundle-splitting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@loadable/webpack-plugin": "^5.13.0",
"@types/loadable__component": "^5.13.0",
"@types/loadable__server": "^5.12.2",
"webpack": "^4.44.2"
"webpack": "^5.0.0"
}
}
22 changes: 21 additions & 1 deletion examples/ssr-with-sass/config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
// eslint-disable-next-line no-undef
// eslint-disable no-undef

const MiniCssExtractPlugin = require('mini-css-extract-plugin');

Check failure on line 3 in examples/ssr-with-sass/config/config.js

View workflow job for this annotation

GitHub Actions / Run

'require' is not defined

Check failure on line 3 in examples/ssr-with-sass/config/config.js

View workflow job for this annotation

GitHub Actions / Run

'require' is not defined
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');

Check failure on line 4 in examples/ssr-with-sass/config/config.js

View workflow job for this annotation

GitHub Actions / Run

'require' is not defined

Check failure on line 4 in examples/ssr-with-sass/config/config.js

View workflow job for this annotation

GitHub Actions / Run

'require' is not defined

module.exports = {

Check failure on line 6 in examples/ssr-with-sass/config/config.js

View workflow job for this annotation

GitHub Actions / Run

'module' is not defined

Check failure on line 6 in examples/ssr-with-sass/config/config.js

View workflow job for this annotation

GitHub Actions / Run

'module' is not defined
// Configuration options for css-minimizer-webpack-plugin
module: {
rules: [
{
test: '/.s?css$/',
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
optimization: {
minizer: [
new CssMinimizerPlugin(),
],
},
plugins: [new MiniCssExtractPlugin()],

default: {
CLIENT_ENTRY: './examples/ssr-with-sass/src/client/index.tsx',
SERVER_ENTRY: './examples/ssr-with-sass/src/server/start.ts',
Expand Down
9 changes: 6 additions & 3 deletions examples/ssr-with-sass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
"autoprefixer": "^10.0.0",
"css-hot-loader": "^1.4.4",
"css-loader": "^4.3.0",
"css-minimizer-webpack-plugin": "^7.0.0",
"mini-css-extract-plugin": "^0.11.2",
"node-sass": "^4.14.1",
"node-sass": "8.0.0",
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
"null-loader": "^4.0.0",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"postcss": "^8.2.10",
"postcss-loader": "^4.0.2",
"resolve-url-loader": "^3.1.0",
"sass-loader": "^10.0.2",
"webpack": "^4.44.2"
"webpack": "^5.0.0"
},
"peerDependencies": {
"webpack": "^5.0.0"
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 2 additions & 2 deletions examples/with-server/src/server/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export interface AppState {}
createServer({
log,
// Use the middleware hook to register your own middleware
middlewareHook: app => {
middlewareHook: (app: { get: (arg0: string, arg1: (_: any, res: any) => any) => void }) => {
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
// Watchtower has setup static file routes by this point

// Add your own routes/middleswares
app.get('/example-route', (_, res) => res.send('<p>Example server route</p>'))
app.get('/example-route', (_: any, res: { send: (arg0: string) => any }) => res.send('<p>Example server route</p>'))

// Watchtower has setup fallback routes to serve your client app for all other routes
},
Expand Down
11 changes: 7 additions & 4 deletions jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
"^bundle-loader": "<rootDir>/lib/test/bundle-loader-mapper.ts"
},
"coverageReporters": ["json", "lcov", "text"],
"globals": {
"ts-jest": {
"tsConfig": "test/tsconfig.test.json"
}
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
}
]
}
}
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@
"dependencies": {
"@babel/core": "^7.11.6",
"@changesets/cli": "^2.10.2",
"@types/assets-webpack-plugin": "^3.9.0",
"@types/express": "^4.17.8",
"@types/html-webpack-plugin": "^3.2.3",
"@types/assets-webpack-plugin": "^7.1.5",
"@types/express": "^4.17.21",
"@types/html-webpack-plugin": "^3.2.9",
"@types/http-proxy-middleware": "^0.19.3",
"@types/jest": "^26.0.14",
"@types/md5": "^2.2.0",
"@types/mkdirp": "^1.0.1",
"@types/node": "^14.11.1",
"@types/node": "18.17.0",
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"@types/react-helmet": "^6.1.0",
Expand All @@ -85,30 +85,30 @@
"@types/serialize-javascript": "^4.0.0",
"@types/supertest": "^2.0.10",
"@types/webpack-bundle-analyzer": "^3.8.0",
"@types/webpack-dev-middleware": "^3.7.2",
"@types/webpack-env": "^1.15.3",
"@types/webpack-hot-middleware": "^2.25.3",
"@types/webpack-merge": "^4.1.5",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"eslint": "^7.9.0",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-wanews": "^2.2.0",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-react-hooks": "^4.6.0",
"express": "^4.17.1",
"jest": "^26.4.2",
"jest": "29.7.0",
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "^2.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet-async": "^1.0.7",
"react-router-dom": "^5.2.0",
"serialize-javascript": "^5.0.1",
"supertest": "^4.0.2",
"ts-jest": "^26.4.0",
"tslib": "^2.0.1",
"typescript": "^4.0.3",
"typescript-log": "^2.0.0"
"ts-jest": "29.1.4",
"tslib": "2.6.2",
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "^5.4.2",
"typescript-log": "^2.0.0",
"webpack": "^5.0.0"
},
"version": "0.0.0"
}
21 changes: 12 additions & 9 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@
"keywords": [],
"scripts": {},
"dependencies": {
"@types/webpack-dev-middleware": "^3.7.2",
"@types/assets-webpack-plugin": "^7.1.5",
"assets-webpack-plugin": "^5.1.1",
"babel-loader": "^8.1.0",
"dotenv": "^8.2.0",
"esbuild-loader": "^2.12.0",
"file-loader": "^6.1.0",
"html-webpack-plugin": "^4.4.1",
"html-webpack-plugin": "^5.6.0",
"http-proxy-middleware": "^1.0.5",
"md5": "^2.3.0",
"mkdirp": "^1.0.4",
"open": "^7.2.1",
"rimraf": "^3.0.2",
"source-map-support": "^0.5.19",
"speed-measure-webpack-plugin": "^1.3.3",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"webpack": "^4.44.2",
"webpack-bundle-analyzer": "^3.9.0",
"webpack-dev-middleware": "^3.7.2",
"webpack-hot-middleware": "^2.25.1",
"webpack-merge": "^5.1.4"
"tsconfig-paths-webpack-plugin": "^4.1.0",
"webpack": "^5.0.0",
"webpack-bundle-analyzer": "^4.10.0",
"webpack-dev-middleware": "^7.2.0",
"webpack-hot-middleware": "^2.26.0",
"webpack-merge": "^5.10.0"
},
"devDependencies": {}
"devDependencies": {},
"peerDependencies": {
"webpack": "^5.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/bin/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function watch(
buildConfig: BuildConfig,
watchProcessEnv: NodeJS.ProcessEnv,
...args: WatchParam[]
): Promise<ChildProcess | WatchServer> {
): Promise<ChildProcess | WatchServer | undefined> {
const { HAS_SERVER } = buildConfig
const additionalStartParams: StartParam[] = []
const env: NodeJS.ProcessEnv = { ...watchProcessEnv }
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function getWebpackConfigInternal(
}

return config
} catch (err) {
} catch (err: any) {
log.error({ err }, 'Error loading webpack config!')
return undefined
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/clean/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function clean(log: Logger, paths: string | string[]): Promise<any> {
log.error({ err }, 'Clean error')
reject(err)
} else {
resolve()
resolve({})
}
})
})
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/config/create-server-externals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import fs from 'fs'
import webpack from 'webpack'
import { ExternalItemFunctionData } from 'webpack'
import path from 'path'
import { CreateWebpackConfigOptions } from '.'


type WebpackExternalFunctionElement = ((
data: ExternalItemFunctionData,
callback: (
err?: null | Error,
result?: string | boolean | string[] | { [index: string]: any }
) => void
) => void)
DownUndaDev marked this conversation as resolved.
Show resolved Hide resolved

export function createServerExternals(
options: CreateWebpackConfigOptions,
): webpack.ExternalsFunctionElement {
): WebpackExternalFunctionElement {
const baseDirNodeModules = path.resolve(options.buildConfig.BASE, 'node_modules')
const nodeModules: string[] = []
if (fs.existsSync(baseDirNodeModules)) {
Expand All @@ -14,7 +24,9 @@ export function createServerExternals(
if (fs.existsSync(cwdNodeModules)) {
nodeModules.push(...fs.readdirSync(cwdNodeModules))
}
return (_context, request, callback) => {
return (data, callback) => {
const request = data.request

if (request === '@project-watchtower/cli') {
resolveFromNodeModules()
} else if (
Expand All @@ -23,14 +35,14 @@ export function createServerExternals(
) {
includeInBundle()
} else if (options.buildConfig.SERVER_BUNDLE_ALL_EXCEPT) {
if (options.buildConfig.SERVER_BUNDLE_ALL_EXCEPT.includes(request)) {
if (request && options.buildConfig.SERVER_BUNDLE_ALL_EXCEPT.includes(request)) {
resolveFromNodeModules()
} else {
includeInBundle()
}
} else if (options.buildConfig.SERVER_INCLUDE_IN_BUNDLE.includes(request)) {
} else if (request && options.buildConfig.SERVER_INCLUDE_IN_BUNDLE.includes(request)) {
includeInBundle()
} else if (nodeModules.includes(request)) {
} else if (request && nodeModules.includes(request)) {
resolveFromNodeModules()
} else {
includeInBundle()
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/config/webpack.client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs'
import path from 'path'
import webpack from 'webpack'
import AssetsPlugin from 'assets-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'

Expand Down Expand Up @@ -44,7 +43,7 @@ export const clientBaseConfig: CreateWebpackConfig = (options) => {
}

const plugins = getPlugins(options.buildConfig)
const resolvePlugins: webpack.ResolvePlugin[] = []
const resolvePlugins: any[] = []

if (SERVER_PUBLIC_DIR) {
const indexHtml = path.resolve(SERVER_PUBLIC_DIR, 'index.html')
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/config/webpack.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import webpack from 'webpack'
import webpack, { WebpackPluginInstance } from 'webpack'
import { CreateWebpackConfigOptions } from '.'
import { createServerExternals } from './create-server-externals'

Expand All @@ -11,14 +11,14 @@ import { createServerExternals } from './create-server-externals'
export const serverBaseConfig = (options: CreateWebpackConfigOptions): webpack.Configuration => {
const { PUBLIC_PATH, SERVER_ENTRY, OUTPUT } = options.buildConfig

const plugins: webpack.Plugin[] = [
const plugins: WebpackPluginInstance[] = [
new webpack.BannerPlugin({
banner: 'require("source-map-support").install();',
entryOnly: false,
raw: true,
}),
]
const resolvePlugins: webpack.ResolvePlugin[] = []
const resolvePlugins: any[] = []

return {
entry: {
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/server/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const getHotReloadMiddleware: HotReloadMiddleware = (log, buildConfig) =>
}
const compiler = webpack(config)

if(compiler === undefined) {
throw new Error('Unable to build compiler')
}

const dev = webpackDevMiddleware(compiler, {
// do not serve index.html on / route
// https://github.com/webpack/webpack-dev-middleware/issues/153
Expand All @@ -46,7 +50,7 @@ export async function openBrowser(log: Logger, port: number) {

try {
await open(`http://localhost:${port}`, { url: true })
} catch (e) {
} catch (e: any) {
log.warn(e, 'Opening browser failed')
}
}
4 changes: 2 additions & 2 deletions packages/cli/src/utils/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Logger } from 'typescript-log'
import webpack from 'webpack'

export const webpackStatsConfig: webpack.Stats.ToStringOptionsObject = {
export const webpackStatsConfig: webpack.StatsOptions = {
children: false,
chunkModules: false,
chunks: false,
Expand All @@ -23,7 +23,7 @@ export const webpackPromise = (log: Logger, config: webpack.Configuration) =>
if (err) {
log.error({ err }, 'Failed to compile')
reject(err)
} else {
} else if(stats) {
printWebpackStats(log, stats)

if (stats.hasErrors()) {
Expand Down
Loading
Loading