From a7181047d5b241ac6c41d056289ab9419e769360 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Thu, 23 Feb 2023 10:54:35 +0200 Subject: [PATCH] Fix windows not being able to build new Feature packages (#7220) * Add missing dev script Signed-off-by: Janne Savolainen * Inline all shared scripts to make them work in all environments Signed-off-by: Janne Savolainen * Switch to using deterministic fake for path.join in unit test Signed-off-by: Janne Savolainen * Make multi export config for webpack not fail when used in windows Signed-off-by: Janne Savolainen --------- Signed-off-by: Janne Savolainen --- package-lock.json | 7 ------- packages/infrastructure/jest/package.json | 3 --- packages/infrastructure/webpack/bin/build.sh | 2 -- packages/infrastructure/webpack/bin/remove-build.sh | 1 - packages/infrastructure/webpack/package.json | 6 +----- .../webpack/src/get-multi-export-config.js | 10 ++++++---- .../webpack/src/get-multi-export-config.test.js | 10 ++++++++++ packages/technical-features/application/package.json | 8 +++----- 8 files changed, 20 insertions(+), 27 deletions(-) delete mode 100755 packages/infrastructure/webpack/bin/build.sh delete mode 100755 packages/infrastructure/webpack/bin/remove-build.sh diff --git a/package-lock.json b/package-lock.json index 6cea9cb6b0..24cae086b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32832,9 +32832,6 @@ "jest-watch-typeahead": "^2.2.1", "lodash": "^4.17.21", "ts-jest": "^29.0.3" - }, - "bin": { - "lens-test": "bin/test.sh" } }, "packages/infrastructure/jest/node_modules/@jest/console": { @@ -34112,10 +34109,6 @@ "webpack": "^5.75.0", "webpack-cli": "^4.10.0", "webpack-node-externals": "^3.0.0" - }, - "bin": { - "lens-build": "bin/build.sh", - "lens-remove-build": "bin/remove-build.sh" } }, "packages/infrastructure/webpack/node_modules/sass-loader": { diff --git a/packages/infrastructure/jest/package.json b/packages/infrastructure/jest/package.json index b0359441dd..b6e00d1369 100644 --- a/packages/infrastructure/jest/package.json +++ b/packages/infrastructure/jest/package.json @@ -15,9 +15,6 @@ }, "license": "MIT", "homepage": "https://github.com/lensapp/lens", - "bin": { - "lens-test": "bin/test.sh" - }, "dependencies": { "@swc/core": "^1.3.20", "@swc/jest": "^0.2.23", diff --git a/packages/infrastructure/webpack/bin/build.sh b/packages/infrastructure/webpack/bin/build.sh deleted file mode 100755 index 589acdeab2..0000000000 --- a/packages/infrastructure/webpack/bin/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -set -e -webpack $@ diff --git a/packages/infrastructure/webpack/bin/remove-build.sh b/packages/infrastructure/webpack/bin/remove-build.sh deleted file mode 100755 index f2421c500d..0000000000 --- a/packages/infrastructure/webpack/bin/remove-build.sh +++ /dev/null @@ -1 +0,0 @@ -rm -rfv build diff --git a/packages/infrastructure/webpack/package.json b/packages/infrastructure/webpack/package.json index 35df41519c..2539a99bb8 100644 --- a/packages/infrastructure/webpack/package.json +++ b/packages/infrastructure/webpack/package.json @@ -15,12 +15,8 @@ }, "license": "MIT", "homepage": "https://github.com/lensapp/lens", - "bin": { - "lens-build": "bin/build.sh", - "lens-remove-build": "bin/remove-build.sh" - }, "scripts": { - "test:unit": "lens-test" + "test:unit": "jest --coverage --runInBand" }, "dependencies": { "@types/webpack-env": "^1.18.0", diff --git a/packages/infrastructure/webpack/src/get-multi-export-config.js b/packages/infrastructure/webpack/src/get-multi-export-config.js index 02944c25d3..338b3d89d7 100644 --- a/packages/infrastructure/webpack/src/get-multi-export-config.js +++ b/packages/infrastructure/webpack/src/get-multi-export-config.js @@ -14,7 +14,7 @@ const { } = require("lodash/fp"); const { pipeline } = require("@ogre-tools/fp"); -module.exports = (packageJson, dependencies = { nodeConfig, reactConfig }) => { +module.exports = (packageJson, dependencies = { nodeConfig, reactConfig, joinPath: path.join }) => { if (!packageJson.lensMultiExportConfig) { throw new Error( `Tried to get multi export config for package "${packageJson.name}" but configuration is missing.` @@ -80,7 +80,9 @@ module.exports = (packageJson, dependencies = { nodeConfig, reactConfig }) => { }; const toExpectedExport = (externalImportPath) => { - const entrypointPath = `./${path.join( + const posixJoinForPackageJson = path.posix.join; + + const entrypointPath = `./${posixJoinForPackageJson( "./dist", externalImportPath, "index.js" @@ -89,7 +91,7 @@ const toExpectedExport = (externalImportPath) => { return [ externalImportPath, { - types: `./${path.join("./dist", externalImportPath, "index.d.ts")}`, + types: `./${posixJoinForPackageJson("./dist", externalImportPath, "index.d.ts")}`, default: entrypointPath, import: entrypointPath, @@ -114,7 +116,7 @@ const toExportSpecificWebpackConfigFor = output: { ...baseConfig.output, - path: path.join(baseConfig.output.path, externalImportPath), + path: dependencies.joinPath(baseConfig.output.path, externalImportPath), }, }; }; diff --git a/packages/infrastructure/webpack/src/get-multi-export-config.test.js b/packages/infrastructure/webpack/src/get-multi-export-config.test.js index 6cad83919f..b0ce1c2231 100644 --- a/packages/infrastructure/webpack/src/get-multi-export-config.test.js +++ b/packages/infrastructure/webpack/src/get-multi-export-config.test.js @@ -1,4 +1,7 @@ import getMultiExportConfig from "./get-multi-export-config"; +import path from 'path'; + +const joinPathFake = path.posix.join; describe("get-multi-export-config", () => { let actual; @@ -52,6 +55,7 @@ describe("get-multi-export-config", () => { actual = getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); expect(actual).toEqual([ @@ -93,6 +97,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' @@ -106,6 +111,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' @@ -119,6 +125,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' @@ -132,6 +139,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config for package "some-name" but configuration is missing.' @@ -145,6 +153,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config for package "some-name" but build types "some-invalid" were not any of "node", "react".' @@ -159,6 +168,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config for package "some-name" but entrypoint was missing for "./some-entrypoint".' diff --git a/packages/technical-features/application/package.json b/packages/technical-features/application/package.json index e5d08f6c49..91f1a6be34 100644 --- a/packages/technical-features/application/package.json +++ b/packages/technical-features/application/package.json @@ -20,11 +20,9 @@ "license": "MIT", "homepage": "https://github.com/lensapp/lens", "scripts": { - "build": "lens-build", - "build:remove": "lens-remove-build", - "code-style:fix": "lens-fix-code-style", - "code-style:verify": "lens-verify-code-style", - "test": "lens-test" + "build": "webpack", + "dev": "webpack --mode=development --watch", + "test": "jest --coverage --runInBand" }, "peerDependencies": { "@ogre-tools/fp": "^12.0.1",