Skip to content

Commit

Permalink
Switch to pnpm (#10576)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Aug 22, 2022
1 parent 96633cc commit 9258f25
Show file tree
Hide file tree
Showing 20 changed files with 17,012 additions and 41,520 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: npm
cache: pnpm
- uses: dorny/paths-filter@v2
id: changes
with:
Expand All @@ -55,29 +56,29 @@ jobs:
- 'package.json'
- 'tsconfig.json'
- name: Install
run: npm ci
run: pnpm install
- name: Lint
run: npm run lint
run: pnpm run lint
- name: Build
run: npm run build
run: pnpm run build
- name: Test
if: |
(steps.changes.outputs.src == 'true' ||
steps.changes.outputs.test == 'true') &&
runner.os != 'Windows'
run: |
npm run build
pnpm run build
if [ "${{ runner.os }}" == "macOS" ]; then
npm run test-ci --browsers chrome,safari
pnpm run test-ci --browsers chrome,safari
else
xvfb-run --auto-servernum npm run test-ci
xvfb-run --auto-servernum pnpm run test-ci
fi
shell: bash
- name: Package
if: steps.changes.outputs.docs == 'true'
run: |
npm run docs
npm pack
pnpm run docs
pnpm pack
- name: Coveralls Parallel - Chrome
if: |
steps.changes.outputs.src == 'true' &&
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/compressed-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
- uses: preactjs/compressed-size-action@v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
Expand All @@ -25,6 +26,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
- uses: andresz1/size-limit-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 6 additions & 5 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: npm
cache: pnpm
- name: Package & Deploy Docs
run: |
npm ci
npm run build
pnpm install
pnpm run build
./scripts/docs-config.sh "master"
npm run docs
npm pack
pnpm run docs
pnpm pack
./scripts/deploy-docs.sh "master"
env:
GITHUB_TOKEN: ${{ secrets.GH_AUTH_TOKEN }}
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
- uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
cache: npm
cache: pnpm
- name: Setup and build
run: |
npm ci
npm install -g json
pnpm install
pnpm install -g json
json -I -f package.json -e "this.version=\"$VERSION\""
json -I -f package-lock.json -e "this.version=\"$VERSION\""
npm run build
pnpm run build
./scripts/docs-config.sh "$VERSION" release
npm run docs
npm pack
pnpm run docs
pnpm pack
env:
VERSION: ${{ needs.setup.outputs.version }}
- name: Publish to NPM
Expand Down Expand Up @@ -68,19 +69,20 @@ jobs:
if: "!github.event.release.prerelease"
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
- uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
cache: npm
cache: pnpm
- name: Setup and build
run: |
npm ci
npm install -g json
pnpm install
pnpm install -g json
json -I -f package.json -e "this.version=\"$VERSION\""
json -I -f package-lock.json -e "this.version=\"$VERSION\""
npm run build
pnpm run build
./scripts/docs-config.sh "$VERSION"
npm run docs
pnpm run docs
env:
VERSION: ${{ needs.setup.outputs.version }}
- name: Deploy Docs
Expand Down
16 changes: 14 additions & 2 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DefaultThemeConfig, defineConfig, PluginTuple } from "vuepress/config";
import * as path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HtmlWebpackInlineSourcePlugin from 'html-webpack-inline-source-plugin';
import markdownItInclude from 'markdown-it-include';
import { DefaultThemeConfig, defineConfig, PluginTuple } from 'vuepress/config';

const docsVersion = "VERSION";
const base: `/${string}/` = process.env.NODE_ENV === "development" ? '/docs/master/' : `/docs/${docsVersion}/`;
Expand All @@ -14,6 +16,16 @@ export default defineConfig({
head: [
['link', {rel: 'icon', href: '/favicon.ico'}],
],
configureWebpack: (config, isServer) => {
configureWebpack: (config) => {
return {
plugins: [
new HtmlWebpackPlugin(),
new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin),
],
};
};
},
plugins: [
'tabs',
['flexsearch'],
Expand All @@ -36,7 +48,7 @@ export default defineConfig({
['vuepress-plugin-typedoc', {
entryPoints: ['../../types/index.d.ts'],
hideInPageTOC: true,
tsconfig: 'tsconfig.json',
tsconfig: path.resolve(__dirname, '../../tsconfig.json'),
},
],
['@simonbrunel/vuepress-plugin-versions', {
Expand Down
22 changes: 11 additions & 11 deletions docs/developers/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ New contributions to the library are welcome, but we ask that you please follow

- Before opening a PR for major additions or changes, please discuss the expected API and/or implementation by [filing an issue](https://github.com/chartjs/Chart.js/issues) or asking about it in the [Chart.js Slack](https://chartjs-slack.herokuapp.com/) #dev channel. This will save you development time by getting feedback upfront and make review faster by giving the maintainers more context and details.
- Consider whether your changes are useful for all users, or if creating a Chart.js [plugin](plugins.md) would be more appropriate.
- Check that your code will pass tests and `eslint` code standards. `npm test` will run both the linter and tests for you.
- Check that your code will pass tests and `eslint` code standards. `pnpm test` will run both the linter and tests for you.
- Add unit tests and document new functionality (in the `test/` and `docs/` directories respectively).
- Avoid breaking changes unless there is an upcoming major release, which is infrequent. We encourage people to write plugins for most new advanced features, and care a lot about backwards compatibility.
- We strongly prefer new methods to be added as private whenever possible. A method can be made private either by making a top-level `function` outside of a class or by prefixing it with `_` and adding `@private` JSDoc if inside a class. Public APIs take considerable time to review and become locked once implemented as we have limited ability to change them without breaking backwards compatibility. Private APIs allow the flexibility to address unforeseen cases.
Expand All @@ -15,32 +15,32 @@ Active committers and contributors are invited to introduce yourself and request

## Building and Testing

Firstly, we need to ensure development dependencies are installed. With node and npm installed, after cloning the Chart.js repo to a local directory, and navigating to that directory in the command line, we can run the following:
Firstly, we need to ensure development dependencies are installed. With node and pnpm installed, after cloning the Chart.js repo to a local directory, and navigating to that directory in the command line, we can run the following:

```bash
> npm install
> pnpm install
```

This will install the local development dependencies for Chart.js.

The following commands are now available from the repository root:

```bash
> npm run build // build dist files in ./dist
> npm run autobuild // build and watch for source changes
> npm run dev // run tests and watch for source and test changes
> npm run lint // perform code linting (ESLint, tsc)
> npm test // perform code linting and run unit tests with coverage
> pnpm run build // build dist files in ./dist
> pnpm run autobuild // build and watch for source changes
> pnpm run dev // run tests and watch for source and test changes
> pnpm run lint // perform code linting (ESLint, tsc)
> pnpm test // perform code linting and run unit tests with coverage
```

`npm run dev` and `npm test` can be appended with a string that is used to match the spec filenames. For example: `npm run dev plugins` will start karma in watch mode for `test/specs/**/*plugin*.js`.
`pnpm run dev` and `pnpm test` can be appended with a string that is used to match the spec filenames. For example: `pnpm run dev plugins` will start karma in watch mode for `test/specs/**/*plugin*.js`.

### Documentation

We use [Vuepress](https://vuepress.vuejs.org/) to manage the docs which are contained as Markdown files in the docs directory. You can run the doc server locally using these commands:

```bash
> npm run docs:dev
> pnpm run docs:dev
```

### Image-Based Tests
Expand All @@ -54,7 +54,7 @@ You can create a new image-based test by following the steps below:
- Create a JS file ([example](https://github.com/chartjs/Chart.js/blob/f7b671006a86201808402c3b6fe2054fe834fd4a/test/fixtures/controller.bubble/radius-scriptable.js)) or JSON file ([example](https://github.com/chartjs/Chart.js/blob/4b421a50bfa17f73ac7aa8db7d077e674dbc148d/test/fixtures/plugin.filler/fill-line-dataset.json)) that defines chart config and generation options.
- Add this file in `test/fixtures/{spec.name}/{feature-name}.json`.
- Add a [describe line](https://github.com/chartjs/Chart.js/blob/4b421a50bfa17f73ac7aa8db7d077e674dbc148d/test/specs/plugin.filler.tests.js#L10) to the beginning of `test/specs/{spec.name}.tests.js` if it doesn't exist yet.
- Run `npm run dev`.
- Run `pnpm run dev`.
- Click the *"Debug"* button (top/right): a test should fail with the associated canvas visible.
- Right click on the chart and *"Save image as..."* `test/fixtures/{spec.name}/{feature-name}.png` making sure not to activate the tooltip or any hover functionality
- Refresh the browser page (`CTRL+R`): test should now pass
Expand Down
33 changes: 33 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "docs",
"private": "true",
"version": "4.0.0-dev",
"license": "MIT",
"type": "module",
"scripts": {
"build": "vuepress build --no-cache",
"dev": "vuepress dev --no-cache"
},
"devDependencies": {
"@simonbrunel/vuepress-plugin-versions": "^0.2.0",
"@vuepress/plugin-google-analytics": "^1.9.7",
"@vuepress/plugin-html-redirect": "^0.1.2",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^4.5.2",
"markdown-it": "^8.4.2",
"markdown-it-include": "^2.0.0",
"typedoc": "^0.23.10",
"typedoc-plugin-markdown": "^3.13.4",
"typescript": "^4.7.4",
"vue": "^2.6.14",
"vue-tabs-component": "^1.5.0",
"vuepress": "^1.9.7",
"vuepress-plugin-code-copy": "^1.0.6",
"vuepress-plugin-flexsearch": "^0.3.0",
"vuepress-plugin-redirect": "^1.2.5",
"vuepress-plugin-tabs": "^0.3.0",
"vuepress-plugin-typedoc": "^0.11.0",
"vuepress-theme-chartjs": "^0.2.0",
"webpack": "^4.46.0"
}
}
2 changes: 1 addition & 1 deletion docs/samples/advanced/derived-axis-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {

## Log2 axis implementation

<<< @/docs/scripts/log2.js
<<< @/scripts/log2.js

## Docs
* [Data structures (`labels`)](../../general/data-structures.html)
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/advanced/derived-chart-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {

## DerivedBubble Implementation

<<< @/docs/scripts/derived-bubble.js
<<< @/scripts/derived-bubble.js

## Docs
* [Bubble Chart](../../charts/bubble.html)
Expand Down
4 changes: 2 additions & 2 deletions docs/samples/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Because of this please don't rely on this file in production environments.

## Functions

<<< @/docs/scripts/utils.js
<<< @/scripts/utils.js

[File on github](https://github.com/chartjs/Chart.js/blob/master/docs/scripts/utils.js)

## Components

Some of the samples make reference to a `components` object. This is an artifact of using a module bundler to build the samples. The creation of that components object is shown below. If chart.js is included as a browser script, these items are accessible via the `Chart` object, i.e `Chart.Tooltip`.

<<< @/docs/scripts/components.js
<<< @/scripts/components.js

[File on github](https://github.com/chartjs/Chart.js/blob/master/docs/scripts/components.js)
14 changes: 13 additions & 1 deletion karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ module.exports = async function(karma) {
);
}

// workaround a karma bug where it doesn't resolve dependencies correctly in
// the same way that Node does
// https://github.com/pnpm/pnpm/issues/720#issuecomment-954120387
const plugins = Object.keys(require('./package').devDependencies).flatMap(
(packageName) => {
if (!packageName.startsWith('karma-')) return []
return [require(packageName)]
}
);

plugins.push(jasmineSeedReporter);

karma.set({
frameworks: ['jasmine'],
plugins: ['karma-*', jasmineSeedReporter],
plugins,
reporters: ['spec', 'kjhtml', 'jasmine-seed'],
browsers: (args.browsers || 'chrome,firefox').split(','),
logLevel: karma.LOG_INFO,
Expand Down
Loading

0 comments on commit 9258f25

Please sign in to comment.