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

Use TypeScript #270

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b4f3620
chore: updated CI action
webdeveric Feb 27, 2024
95e1ce1
chore: updated settings
webdeveric Feb 27, 2024
fddf016
chore(deps): updated dependencies
webdeveric Feb 27, 2024
a766266
chore: updating linting config
webdeveric Feb 27, 2024
11c2588
chore: updated configs
webdeveric Feb 27, 2024
b34b558
refactor: use TypeScript
webdeveric Feb 27, 2024
13d4baf
test: use `vitest`
webdeveric Feb 27, 2024
e4a85b4
chore: updated examples
webdeveric Feb 27, 2024
a0cc67c
chore: updated tuple key
webdeveric Feb 27, 2024
6efd4ba
chore: updated readme
webdeveric Feb 27, 2024
823c608
test: expect less specific error
webdeveric Feb 27, 2024
a1eb3e1
chore(deps): bump min webpack version
webdeveric Feb 27, 2024
7f6052c
test: updated dev server tests
webdeveric Feb 27, 2024
08ef639
chore(deps): updated dependencies
webdeveric Feb 27, 2024
e149c1a
chore: bumped min webpack version
webdeveric Feb 27, 2024
178182a
chore(deps): updated dependencies
webdeveric Mar 6, 2024
c10dc7b
chore: added `typesVersions`
webdeveric Mar 6, 2024
714d380
chore(deps): updated dependencies
webdeveric Mar 8, 2024
fbe743c
chore(deps): updated dependencies
webdeveric Mar 12, 2024
daa2a7a
chore(deps): updated dependencies
webdeveric Mar 25, 2024
a0fe88f
chore(deps): added `validate-package-exports`
webdeveric Mar 25, 2024
9d375d1
chore(deps): updated dependencies
webdeveric Mar 29, 2024
61860b8
chore(deps): updated dependencies
webdeveric Apr 3, 2024
95c2891
chore: updated types for testing
webdeveric Apr 3, 2024
464fcb5
chore(deps): updated dependencies
webdeveric Apr 28, 2024
1a3584f
chore(deps): updated dependencies
webdeveric Apr 28, 2024
f1b8613
chore: updated config
webdeveric May 13, 2024
66b8592
chore: spell check commit message
webdeveric May 13, 2024
37d655d
chore(deps): updated dependencies
webdeveric May 13, 2024
a27fd38
chore: removed `--config`
webdeveric May 13, 2024
ec82c66
chore(deps): updated dependencies
webdeveric Jul 14, 2024
1515f8f
chore(linting): use shorthand
webdeveric Jul 14, 2024
afffc0d
chore(prettier): ran `format`
webdeveric Jul 14, 2024
d589b2a
chore(ci): updated `matrix.node-version`
webdeveric Jul 14, 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
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

69 changes: 69 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"root": true,
"extends": ["@webdeveric/eslint-config-ts", "plugin:import/recommended", "plugin:import/typescript", "prettier"],
"env": {
"es6": true,
"node": true
},
"parserOptions": {
"project": ["./tsconfig.json"],
"EXPERIMENTAL_useProjectService": {
"maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING": 1000
}
},
"settings": {
"import/extensions": [".ts", ".mts", ".cts", ".js", ".json"],
"import/resolver": {
"typescript": {
"project": "./tsconfig.json"
},
"node": {
"extensions": [".js", ".ts", ".mts", ".cts"]
}
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".mts", ".cts"]
}
},
"rules": {
"import/first": "error",
"import/no-absolute-path": "error",
"import/no-cycle": "error",
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["./vitest.config.mts", "./lint-staged.config.mjs", "./test/**/*"]
}
],
"import/no-relative-packages": "error",
"import/no-self-import": "error",
"import/no-unresolved": "error",
"import/no-useless-path-segments": [
"error",
{
"noUselessIndex": false
}
],
"import/order": [
"error",
{
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"groups": ["builtin", "external", "internal", "parent", ["sibling", "index"], "type"],
"newlines-between": "always"
}
],
"sort-imports": "off"
},
"overrides": [
{
"files": ["**/*.test.ts"],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}
40 changes: 23 additions & 17 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,37 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [18.x, 20.x]
webpack-version: ["5.2.0", 5]
dev-server-version: ["3.6.0", 3]
css-loader-version: ["3.5.0", latest]
node-version: [20.x, 22.x]
webpack-version: ['5.61.0', latest]
dev-server-version: [4, latest]
css-loader-version: ['3.5.0', latest]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Installing dependencies
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
- name: Installing specific dependency versions
run: pnpm install webpack@${{ matrix.webpack-version }} webpack-dev-server@${{ matrix.dev-server-version }} css-loader@${{ matrix.css-loader-version }}
- name: Building (if needed)
run: pnpm --if-present run build
- name: Running tests
run: pnpm test
- name: Generating coverage report
run: pnpm lcov

- name: Install specific dependency versions
run: pnpm install webpack@${{ matrix.webpack-version }} webpack-dev-server@${{ matrix.dev-server-version }} css-loader@${{ matrix.css-loader-version }} --no-lockfile

- name: Build
run: pnpm build

- name: Test
run: pnpm coverage

- name: Upload code coverage
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: ./coverage.lcov
token: ${{ secrets.CODECOV_TOKEN }}
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
node_modules
npm-debug.log
coverage.lcov
.nyc_output/
.idea/
cache/
coverage/
dist/
private/
.idea/
*.tsbuildinfo
npm-debug.log
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no cspell -- --no-summary --no-progress --language-id commit-msg $1
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pnpm-lock.yaml
.editorconfig
.npmrc
.nvmrc
.eslintrc*
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"javascript.preferences.importModuleSpecifierEnding": "js",
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.preferences.preferTypeOnlyAutoImports": true
"typescript.preferences.preferTypeOnlyAutoImports": true,
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.referencesCodeLens.enabled": true,
"typescript.surveys.enabled": false,
"typescript.implementationsCodeLens.enabled": true
}
14 changes: 13 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@
"instanceof",
"integrityhashes",
"lcov",
"memfs",
"nvmrc",
"postbuild",
"prebuild",
"prefetch",
"preload",
"subpage",
"subresource",
"tapable",
"Testerson",
"tsbuildinfo",
"typecheck",
"vitest",
"webdeveric"
],
"flagWords": [],
"ignorePaths": ["pnpm-lock.yaml", "./.vscode/", "node_modules"]
"ignorePaths": ["pnpm-lock.yaml", "./.vscode/", "node_modules"],
"languageSettings": [
{
"languageId": "commit-msg",
"ignoreRegExpList": ["/^#.*/gm"]
}
]
}
2 changes: 1 addition & 1 deletion examples/asset-integrity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'asset-integrity-manifest.json',
Expand Down
4 changes: 2 additions & 2 deletions examples/asset-size.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'asset-size-manifest.json',
Expand All @@ -8,7 +8,7 @@ const manifest = new WebpackAssetsManifest({
value: entry.value,
// `size()` returns number of bytes
size: asset.source.size(),
}
},
};
},
});
4 changes: 2 additions & 2 deletions examples/aws-s3-data-integrity.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'aws-s3-data-integrity-manifest.json',
integrity: true,
integrityHashes: [ 'md5' ],
integrityHashes: ['md5'],
integrityPropertyName: 'md5',
publicPath: 's3://some-bucket/some-folder/',
customize(entry, original, manifest, asset) {
Expand Down
13 changes: 8 additions & 5 deletions examples/custom-cdn.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'custom-cdn-manifest.json',
publicPath(filename, manifest)
{
switch ( manifest.getExtension( filename ).substr(1).toLowerCase() ) {
case 'jpg': case 'jpeg': case 'gif': case 'png': case 'svg':
publicPath(filename, manifest) {
switch (manifest.getExtension(filename).substring(1).toLowerCase()) {
case 'jpg':
case 'jpeg':
case 'gif':
case 'png':
case 'svg':
return `https://img.cdn.example.com/${filename}`;
case 'css':
return `https://css.cdn.example.com/${filename}`;
Expand Down
34 changes: 18 additions & 16 deletions examples/customized.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'customized-manifest.json',
// This will allow you to customize each individual entry in the manifest.
customize(entry, original, manifest, asset) {
if ( manifest.isMerging ) {
if (manifest.isMerging) {
// Do something
}

// You can prevent adding items to the manifest by returning false.
if ( entry.key.toLowerCase().endsWith('.map') ) {
return false;
}
if (manifest.utils.isKeyValuePair(entry)) {
// You can prevent adding items to the manifest by returning false.
if (entry.key.toLowerCase().endsWith('.map')) {
return false;
}

// You can directly modify key/value on the `entry` argument
// or you can return a new object that has key and/or value properties.
// If either the key or value is missing, the defaults will be used.
//
// The key should be a string and the value can be anything that can be JSON stringified.
// If something else (or nothing) is returned, the manifest will add the entry normally.
return {
key: `src/${entry.key}`,
value: `dist/${entry.value}`,
};
// You can directly modify key/value on the `entry` argument
// or you can return a new object that has key and/or value properties.
// If either the key or value is missing, the defaults will be used.
//
// The key should be a string and the value can be anything that can be JSON stringified.
// If something else (or nothing) is returned, the manifest will add the entry normally.
return {
key: `src/${entry.key}`,
value: `dist/${entry.value}`,
};
}
},
});
4 changes: 2 additions & 2 deletions examples/merged.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'merged-manifest.json',
merge: true,
customize(entry, original, manifest, asset) {
if ( manifest.isMerging ) {
if (manifest.isMerging) {
// Do something
}
},
Expand Down
6 changes: 3 additions & 3 deletions examples/sorted.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

const manifest = new WebpackAssetsManifest({
output: 'sorted-manifest.json',
Expand All @@ -7,11 +7,11 @@ const manifest = new WebpackAssetsManifest({
const extA = this.getExtension(a);
const extB = this.getExtension(b);

if ( extA > extB ) {
if (extA > extB) {
return 1;
}

if ( extA < extB ) {
if (extA < extB) {
return -1;
}

Expand Down
9 changes: 4 additions & 5 deletions examples/transformed.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const WebpackAssetsManifest = require('webpack-assets-manifest');
import { WebpackAssetsManifest } from 'webpack-assets-manifest';

import { name, version } from 'webpack-assets-manifest/package.json';

const manifest = new WebpackAssetsManifest({
output: 'transformed-manifest.json',
transform(assets, manifest) {
// Attach new properties to `assets` or return something else.
// Just be sure it can be JSON stringified.

const { name, version } = require('./package.json');

assets.package = {
name,
version,
Expand All @@ -19,6 +18,6 @@ const manifest = new WebpackAssetsManifest({
value: 'YourValue',
});

assets[ key ] = value;
assets[key] = value;
},
});
27 changes: 27 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { relative } from 'node:path';
import { cwd } from 'node:process';

/**
* @type {(filenames: string[]) => string[]>}
*/
const relativeFilenames = (filenames) => {
const root = cwd();

return filenames.map((file) => relative(root, file));
};

/**
* @type {Record<string, string | (filenames: string[]) => string | string[] | Promise<string | string[]>}
*/
export default {
'*.{js,cjs,mjs,ts,cts,mts}': ['eslint --fix', 'prettier --write'],
'*.{json,md}': 'prettier --write',
'*': (filenames) => {
const files = relativeFilenames(filenames);

return [
`cspell lint --no-progress --no-summary --no-must-find-files ${files.join(' ')}`,
`sh -c 'echo "${files.join('\n')}" | cspell --show-context stdin'`, // Spell check file names.
];
},
};
Loading
Loading