From 42dbf8e2123430291ef9610bbeb12d5c36b8755f Mon Sep 17 00:00:00 2001 From: Eduardo Fungairino Date: Fri, 15 Nov 2024 10:56:03 -0500 Subject: [PATCH] refactoring utils project to use barrel output (#9524) --- .github/workflows/ci.yml | 2 +- applications/browser-extension/package.json | 3 ++- .../src/pageEditor/store/editor/editorSlice.ts | 2 +- applications/browser-extension/tsconfig.json | 2 +- knip.mjs | 6 ++++-- libraries/{utils => util-debug}/.eslintrc.js | 0 libraries/{utils => util-debug}/jest.config.js | 0 libraries/{utils => util-debug}/package.json | 10 ++++++---- libraries/util-debug/src/index.ts | 18 ++++++++++++++++++ .../src/lib}/debugUtils.test.ts | 0 .../src => util-debug/src/lib}/debugUtils.ts | 0 .../src => util-debug/src/lib}/globals.d.ts | 0 libraries/{utils => util-debug}/tsconfig.json | 0 .../{utils => util-debug}/tsconfig.lib.json | 0 .../{utils => util-debug}/tsconfig.test.json | 2 +- nx.json | 5 +++++ package-lock.json | 11 +++++------ package.json | 1 + pixiebrix-extension.iml | 2 +- tsconfig.json | 2 +- 20 files changed, 47 insertions(+), 19 deletions(-) rename libraries/{utils => util-debug}/.eslintrc.js (100%) rename libraries/{utils => util-debug}/jest.config.js (100%) rename libraries/{utils => util-debug}/package.json (73%) create mode 100644 libraries/util-debug/src/index.ts rename libraries/{utils/src => util-debug/src/lib}/debugUtils.test.ts (100%) rename libraries/{utils/src => util-debug/src/lib}/debugUtils.ts (100%) rename libraries/{utils/src => util-debug/src/lib}/globals.d.ts (100%) rename libraries/{utils => util-debug}/tsconfig.json (100%) rename libraries/{utils => util-debug}/tsconfig.lib.json (100%) rename libraries/{utils => util-debug}/tsconfig.test.json (84%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3f3c8099b..ab41c408b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: node-version-file: applications/browser-extension/package.json cache: npm - run: npm ci - - run: npm run test --workspaces -- --coverage + - run: npm run test:ci - uses: actions/upload-artifact@v4 with: name: extension-test-coverage diff --git a/applications/browser-extension/package.json b/applications/browser-extension/package.json index 6e1d9089f1..934418c13c 100644 --- a/applications/browser-extension/package.json +++ b/applications/browser-extension/package.json @@ -4,6 +4,7 @@ "description": "PixieBrix Browser Extension", "scripts": { "test": "TZ=UTC jest", + "test:ci": "TZ=UTC jest --coverage", "test:watch": "TZ=UTC jest --watchAll", "test:e2e": "playwright test", "test:e2e:debug": "PWDEBUG=console playwright test", @@ -40,7 +41,7 @@ "@fortawesome/react-fontawesome": "^0.2.2", "@mozilla/readability": "^0.5.0", "@pixiebrix/jq-web": "^0.5.1", - "@pixiebrix/utils": "*", + "@pixiebrix/util-debug": "*", "@reduxjs/toolkit": "^1.9.7", "@rjsf/bootstrap-4": "^5.22.3", "@rjsf/core": "^5.22.3", diff --git a/applications/browser-extension/src/pageEditor/store/editor/editorSlice.ts b/applications/browser-extension/src/pageEditor/store/editor/editorSlice.ts index c8dc470625..7ea182b2e8 100644 --- a/applications/browser-extension/src/pageEditor/store/editor/editorSlice.ts +++ b/applications/browser-extension/src/pageEditor/store/editor/editorSlice.ts @@ -34,7 +34,7 @@ import { uuidv4 } from "@/types/helpers"; import { cloneDeep, compact, get, pull, uniq } from "lodash"; import { DataPanelTabKey } from "@/pageEditor/tabs/editTab/dataPanel/dataPanelTypes"; import { type TreeExpandedState } from "@/components/jsonTree/JsonTree"; -import { getInvalidPath } from "@pixiebrix/utils/src/debugUtils"; +import { getInvalidPath } from "@pixiebrix/util-debug"; import { selectActiveBrickConfigurationUIState, selectActiveBrickPipelineUIState, diff --git a/applications/browser-extension/tsconfig.json b/applications/browser-extension/tsconfig.json index 722e205152..5216f4ff79 100644 --- a/applications/browser-extension/tsconfig.json +++ b/applications/browser-extension/tsconfig.json @@ -17,7 +17,7 @@ // All project dependencies // TODO: add @nx/js plugin which will automatically update these paths { - "path": "../../libraries/utils" + "path": "../../libraries/util-debug" } ], "exclude": ["venv", "dist", "node_modules"] diff --git a/knip.mjs b/knip.mjs index 4555a20dfe..eeb9168298 100644 --- a/knip.mjs +++ b/knip.mjs @@ -36,8 +36,10 @@ const knipConfig = { ], }, "libraries/*": { - entry: "src/*.ts!", - project: "**/*.ts", + // ! suffix files are included in production mode + entry: "src/index.ts!", + project: ["src/**/*.ts!"], + ignore: ["src/lib/globals.d.ts"], }, "applications/browser-extension": { entry: [ diff --git a/libraries/utils/.eslintrc.js b/libraries/util-debug/.eslintrc.js similarity index 100% rename from libraries/utils/.eslintrc.js rename to libraries/util-debug/.eslintrc.js diff --git a/libraries/utils/jest.config.js b/libraries/util-debug/jest.config.js similarity index 100% rename from libraries/utils/jest.config.js rename to libraries/util-debug/jest.config.js diff --git a/libraries/utils/package.json b/libraries/util-debug/package.json similarity index 73% rename from libraries/utils/package.json rename to libraries/util-debug/package.json index 6fd0a5eabf..450ac49da5 100644 --- a/libraries/utils/package.json +++ b/libraries/util-debug/package.json @@ -1,16 +1,18 @@ { - "name": "@pixiebrix/utils", + "name": "@pixiebrix/util-debug", "version": "1.0.0", - "description": "PixieBrix Utility Library", + "description": "PixieBrix Debug Utility Library", "scripts": { "test": "TZ=UTC jest", + "test:ci": "TZ=UTC jest", "lint": "eslint src --ext js,jsx,ts,tsx --quiet --report-unused-disable-directives", "lint:fast": "ESLINT_NO_IMPORTS=1 eslint src --ext js,jsx,ts,tsx --quiet", "build": "tsc --build", "build:typecheck": "tsc --build" }, - "license": "AGPL-3.0", - "repository": "https://github.com/pixiebrix/pixiebrix-extension", + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", + "sideEffects": false, "dependencies": { "formik": "^2.4.6" }, diff --git a/libraries/util-debug/src/index.ts b/libraries/util-debug/src/index.ts new file mode 100644 index 0000000000..9fb236c5a0 --- /dev/null +++ b/libraries/util-debug/src/index.ts @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2024 PixieBrix, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export * from "./lib/debugUtils"; diff --git a/libraries/utils/src/debugUtils.test.ts b/libraries/util-debug/src/lib/debugUtils.test.ts similarity index 100% rename from libraries/utils/src/debugUtils.test.ts rename to libraries/util-debug/src/lib/debugUtils.test.ts diff --git a/libraries/utils/src/debugUtils.ts b/libraries/util-debug/src/lib/debugUtils.ts similarity index 100% rename from libraries/utils/src/debugUtils.ts rename to libraries/util-debug/src/lib/debugUtils.ts diff --git a/libraries/utils/src/globals.d.ts b/libraries/util-debug/src/lib/globals.d.ts similarity index 100% rename from libraries/utils/src/globals.d.ts rename to libraries/util-debug/src/lib/globals.d.ts diff --git a/libraries/utils/tsconfig.json b/libraries/util-debug/tsconfig.json similarity index 100% rename from libraries/utils/tsconfig.json rename to libraries/util-debug/tsconfig.json diff --git a/libraries/utils/tsconfig.lib.json b/libraries/util-debug/tsconfig.lib.json similarity index 100% rename from libraries/utils/tsconfig.lib.json rename to libraries/util-debug/tsconfig.lib.json diff --git a/libraries/utils/tsconfig.test.json b/libraries/util-debug/tsconfig.test.json similarity index 84% rename from libraries/utils/tsconfig.test.json rename to libraries/util-debug/tsconfig.test.json index 7ab9490ad1..442c2ee211 100644 --- a/libraries/utils/tsconfig.test.json +++ b/libraries/util-debug/tsconfig.test.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "../../dist/out-tsc/libraries/utils", + "outDir": "../../dist/out-tsc/libraries/util-debug", "types": ["jest", "node"] }, "include": [ diff --git a/nx.json b/nx.json index 4235c0198a..30bf0d6e6c 100644 --- a/nx.json +++ b/nx.json @@ -7,6 +7,11 @@ "cache": true }, "test": { + "dependsOn": ["^build:typecheck"], + "cache": true + }, + "test:ci": { + "dependsOn": ["^build:typecheck"], "cache": true }, "lint": { diff --git a/package-lock.json b/package-lock.json index 6203d8ba00..184408d4f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "@fortawesome/react-fontawesome": "^0.2.2", "@mozilla/readability": "^0.5.0", "@pixiebrix/jq-web": "^0.5.1", - "@pixiebrix/utils": "*", + "@pixiebrix/util-debug": "*", "@reduxjs/toolkit": "^1.9.7", "@rjsf/bootstrap-4": "^5.22.3", "@rjsf/core": "^5.22.3", @@ -309,10 +309,9 @@ "version": "0.0.1", "extraneous": true }, - "libraries/utils": { - "name": "@pixiebrix/utils", + "libraries/util-debug": { + "name": "@pixiebrix/util-debug", "version": "1.0.0", - "license": "AGPL-3.0", "dependencies": { "formik": "^2.4.6" }, @@ -4437,8 +4436,8 @@ "resolved": "https://registry.npmjs.org/@pixiebrix/jq-web/-/jq-web-0.5.1.tgz", "integrity": "sha512-q99g6J8UVsS7+pNlxyl01eDnUtHuYC9GPgKUXntpfs7akuqhkes9AZjC678LxjTC5BkjFtfOQazFQoyW/9/B/w==" }, - "node_modules/@pixiebrix/utils": { - "resolved": "libraries/utils", + "node_modules/@pixiebrix/util-debug": { + "resolved": "libraries/util-debug", "link": true }, "node_modules/@pkgjs/parseargs": { diff --git a/package.json b/package.json index 3056021b57..17fe4a612b 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ ], "scripts": { "test": "nx run-many -t test", + "test:ci": "nx run-many -t test:ci", "lint": "nx run-many -t lint", "build": "nx build", "build:typecheck": "nx run-many -t build:typecheck", diff --git a/pixiebrix-extension.iml b/pixiebrix-extension.iml index 96e4a0616e..eb7cb662e7 100644 --- a/pixiebrix-extension.iml +++ b/pixiebrix-extension.iml @@ -11,8 +11,8 @@ - + diff --git a/tsconfig.json b/tsconfig.json index ef27631278..c8cc45c34a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "path": "./applications/browser-extension" }, { - "path": "./libraries/utils" + "path": "./libraries/util-debug" } ] }