Skip to content

Commit 2e3df3d

Browse files
committed
wip
1 parent 84454e1 commit 2e3df3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+10051
-3624
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": ["**/*"],
4+
"plugins": ["@nx"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"rules": {
9+
"@nx/enforce-module-boundaries": [
10+
"error",
11+
{
12+
"enforceBuildableLibDependency": true,
13+
"allow": [],
14+
"depConstraints": [
15+
{
16+
"sourceTag": "*",
17+
"onlyDependOnLibsWithTags": ["*"]
18+
}
19+
]
20+
}
21+
]
22+
}
23+
},
24+
{
25+
"files": ["*.ts", "*.tsx"],
26+
"extends": ["plugin:@nx/typescript"],
27+
"rules": {}
28+
},
29+
{
30+
"files": ["*.js", "*.jsx"],
31+
"extends": ["plugin:@nx/javascript"],
32+
"rules": {}
33+
}
34+
]
35+
}

.prettierignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Add files here to ignore them from prettier formatting
2+
/dist
3+
/coverage
4+
/.nx/cache
5+
/.nx/workspace-data

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

.vscode/extensions.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"recommendations": [
3-
4-
"nrwl.angular-console"
5-
]
2+
"recommendations": ["nrwl.angular-console", "esbenp.prettier-vscode"]
63
}

CONTRIBUTING.MD

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,27 @@
1010

1111
#### Setup
1212

13+
**Add a library**
1314
To create a new library in the monorepo, run the following command:
1415

1516
```bash
1617

17-
npx nx g @nx/js:lib [package-name] --tags=scope:plugin --projectNameAndRootFormat=derived --unitTestRunner=vitest --bundler=esbuild
18+
npx nx g @nx/js:lib [package-name] --directory=packages/[package-name] --projectNameAndRootFormat=as-provided --bundler=esbuild --unitTestRunner=vitest --module=esm --tags=scope:plugin
1819

1920
```
21+
22+
**Add an e2e test project**
23+
24+
To create a new e2e test project in the monorepo, run the following command:
25+
26+
```bash
27+
npx nx g @nx/js:lib e2e-[package-name] --directory=e2e/[package-name] --projectNameAndRootFormat=as-provided --bundler=none --unitTestRunner=vitest --tags=type:e2e
28+
```
29+
30+
31+
32+
Notes:
33+
- The project bundle-size is using the 'generatePackageJson' option which is deprecated for library projects. It should only be used for applications.
34+
For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/nx-api/eslint-plugin/documents/dependency-checks).
35+
36+
// generate testing helper lib testing/utils with name testing-utils

e2e/bundle-size/.eslintrc.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["*.json"],
19+
"parser": "jsonc-eslint-parser",
20+
"rules": {
21+
"@nx/dependency-checks": [
22+
"error",
23+
{
24+
"ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
25+
}
26+
]
27+
}
28+
}
29+
]
30+
}

e2e/bundle-size/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# e2e-bundle-size
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
Run `nx build e2e-bundle-size` to build the library.
8+
9+
## Running unit tests
10+
11+
Run `nx test e2e-bundle-size` to execute the unit tests via [Vitest](https://vitest.dev/).

e2e/bundle-size/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "e2e-bundle-size",
3+
"version": "0.0.1",
4+
"dependencies": {},
5+
"type": "commonjs",
6+
"main": "./index.cjs",
7+
"private": true
8+
}

e2e/bundle-size/project.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "e2e-bundle-size",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "e2e/bundle-size/src",
5+
"projectType": "library",
6+
"tags": ["type:e2e"],
7+
"implicitDependencies": ["bundle-size"],
8+
"targets": {
9+
"test": {
10+
"dependsOn": ["^build"],
11+
"executor": "@nx/vite:test",
12+
"outputs": ["{options.reportsDirectory}"],
13+
"options": {
14+
"reportsDirectory": "../../coverage/e2e/bundle-size"
15+
}
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`execute-plugin-bundle-size > should run bundle-size plugin and create valid report.json 1`] = `
4+
{
5+
"categories": [],
6+
"packageName": "@code-pushup/core",
7+
"plugins": [
8+
{
9+
"audits": [
10+
{
11+
"description": "Bundle size audit",
12+
"score": 1,
13+
"slug": "bundle-size",
14+
"title": "Bundle size",
15+
"value": 1,
16+
},
17+
],
18+
"description": "Bundle size plugin for Code PushUp",
19+
"icon": "folder-css",
20+
"slug": "bundle-size",
21+
"title": "Bundle size",
22+
},
23+
],
24+
}
25+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {afterEach, beforeEach, describe, expect, it} from "vitest";
2+
import {
3+
addCodePushupConfigFile, cleanTestFolder,
4+
executeCliCollectForPlugin,
5+
getRelativePathToPluginDist, omitVariableReportData,
6+
readReportJson
7+
} from "testing-utils";
8+
import {resolve} from "path";
9+
import {Report, reportSchema} from "@code-pushup/models";
10+
11+
describe('execute-plugin-bundle-size', () => {
12+
const baseDir = resolve('tmp/e2e/execute-plugin-bundle-size');
13+
14+
beforeEach(async () => {
15+
await addCodePushupConfigFile( {
16+
fileImports: [`import {bundleSizePlugin} from "${getRelativePathToPluginDist(baseDir, 'bundle-size')}";`],
17+
pluginStrings: ['bundleSizePlugin()'],
18+
targetFolder: baseDir
19+
});
20+
});
21+
22+
afterEach(async () => {
23+
await cleanTestFolder(baseDir);
24+
});
25+
26+
it('should run bundle-size plugin and create valid report.json', async () => {
27+
const { code, stderr } = await executeCliCollectForPlugin('bundle-size', {}, baseDir);
28+
expect(code).toBe(0);
29+
30+
const report: Report = await readReportJson(baseDir);
31+
expect(() => reportSchema.parse(report)).not.toThrow();
32+
expect(omitVariableReportData(report)).toMatchSnapshot();
33+
});
34+
35+
it('should run bundle-size plugin with the correct slug and audits in report.json', async () => {
36+
const { code, stderr } = await executeCliCollectForPlugin('bundle-size', {}, baseDir);
37+
expect(code).toBe(0);
38+
39+
const report: Report = await readReportJson(baseDir);
40+
expect(report.plugins.at(0)?.slug).toBe('bundle-size');
41+
expect(report.plugins.at(0)?.audits.length).toBe(1);
42+
expect(report.plugins.at(0)?.audits.at(0)?.slug).toBe('bundle-size');
43+
44+
});
45+
});

e2e/bundle-size/tsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"forceConsistentCasingInFileNames": true,
6+
"strict": true,
7+
"noImplicitOverride": true,
8+
"noPropertyAccessFromIndexSignature": true,
9+
"noImplicitReturns": true,
10+
"noFallthroughCasesInSwitch": true,
11+
"types": ["vitest"]
12+
},
13+
"files": [],
14+
"include": [],
15+
"references": [
16+
{
17+
"path": "./tsconfig.spec.json"
18+
}
19+
]
20+
}

e2e/bundle-size/tsconfig.spec.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"types": [
6+
"vitest/globals",
7+
"vitest/importMeta",
8+
"vite/client",
9+
"node",
10+
"vitest"
11+
]
12+
},
13+
"include": [
14+
"src/**/*.ts",
15+
"mock/**/*.ts",
16+
"vite.config.ts",
17+
"vitest.config.ts",
18+
"src/**/*.test.ts",
19+
"src/**/*.spec.ts",
20+
"src/**/*.test.tsx",
21+
"src/**/*.spec.tsx",
22+
"src/**/*.test.js",
23+
"src/**/*.spec.js",
24+
"src/**/*.test.jsx",
25+
"src/**/*.spec.jsx",
26+
"src/**/*.d.ts"
27+
]
28+
}

e2e/bundle-size/vite.config.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { defineConfig } from 'vite';
2+
3+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4+
5+
export default defineConfig({
6+
root: __dirname,
7+
cacheDir: '../../node_modules/.vite/e2e/bundle-size',
8+
9+
plugins: [nxViteTsPaths()],
10+
11+
// Uncomment this if you are using workers.
12+
// worker: {
13+
// plugins: [ nxViteTsPaths() ],
14+
// },
15+
16+
test: {
17+
watch: false,
18+
globals: true,
19+
cache: { dir: '../../node_modules/.vitest/e2e/bundle-size' },
20+
environment: 'node',
21+
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
22+
reporters: ['default'],
23+
coverage: {
24+
reportsDirectory: '../../coverage/e2e/bundle-size',
25+
provider: 'v8',
26+
},
27+
},
28+
});

nx.json

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
11
{
2+
"pluginsConfig": {
3+
"@nx/js": {
4+
"analyzeSourceFiles": true
5+
}
6+
},
27
"extends": "nx/presets/npm.json",
38
"$schema": "./node_modules/nx/schemas/nx-schema.json",
49
"nxCloudAccessToken": "OWI2YzgxYTgtZWMzZi00MWFiLWE4YjYtM2Q4MjRjMGNjOTg0fHJlYWQtd3JpdGU=",
510
"workspaceLayout": {
611
"appsDir": "packages",
712
"libsDir": "packages"
8-
}
13+
},
14+
"targetDefaults": {
15+
"@nx/esbuild:esbuild": {
16+
"cache": true,
17+
"dependsOn": ["^build"],
18+
"inputs": ["default", "^default"]
19+
},
20+
"@nx/vite:test": {
21+
"cache": true,
22+
"inputs": ["default", "^default"]
23+
}
24+
},
25+
"plugins": [
26+
{
27+
"plugin": "@nx/eslint/plugin",
28+
"options": {
29+
"targetName": "lint"
30+
}
31+
},
32+
{
33+
"plugin": "@nx/rollup/plugin",
34+
"options": {
35+
"buildTargetName": "build"
36+
}
37+
}
38+
]
939
}

0 commit comments

Comments
 (0)