Skip to content

Commit 76c902b

Browse files
committed
Merge branch 'develop' of github.com:privatenumber/webpack-localize-assets-plugin
2 parents 3b96eac + 88dfc8a commit 76c902b

44 files changed

Lines changed: 4571 additions & 5358 deletions

Some content is hidden

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

.github/workflows/release.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v2
15-
- name: Use Node.js ${{ matrix.node-version }}
16-
uses: actions/setup-node@v1
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version-file: '.nvmrc'
20+
21+
- name: Setup pnpm
22+
uses: pnpm/[email protected]
1723
with:
18-
node-version: 14.x
19-
- name: Install dependencies
20-
run: npx ci
24+
version: 7
25+
run_install: true
26+
2127
- name: Test
22-
run: npm run test # Produces distribution via pretest
28+
run: pnpm test # Produces distribution via pretest
29+
2330
- name: Lint
24-
run: npm run lint
31+
run: pnpm lint
32+
2533
- name: Release
2634
env:
2735
GH_TOKEN: ${{ secrets.GH_TOKEN }}
2836
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
29-
run: npx semantic-release
37+
run: pnpm dlx semantic-release

.github/workflows/test.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,37 @@ name: Test
22

33
on:
44
push:
5-
branches: [develop]
5+
branches: develop
66
pull_request:
7-
branches: [master, develop]
87

98
jobs:
109
test:
1110
name: Test
1211
runs-on: ubuntu-latest
1312

14-
strategy:
15-
matrix:
16-
node-version: [12.x, 14.x]
17-
1813
steps:
1914
- name: Checkout
20-
uses: actions/checkout@v2
21-
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v1
15+
uses: actions/checkout@v3
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v3
2319
with:
24-
node-version: ${{ matrix.node-version }}
25-
- name: Install dependencies
26-
run: npx ci
27-
- name: Test
28-
run: npm run test
20+
node-version-file: '.nvmrc'
21+
22+
- name: Setup pnpm
23+
uses: pnpm/[email protected]
24+
with:
25+
version: 7
26+
run_install: true
27+
2928
- name: Lint
30-
run: npm run lint
29+
run: pnpm lint
30+
31+
- name: Type check
32+
run: pnpm type-check
33+
34+
- name: Build
35+
run: pnpm build
36+
37+
- name: Test
38+
run: pnpm test

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shell-emulator=true

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v14.16.1
1+
v16.17.0

README.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ Required
5858

5959
Type:
6060
```ts
61-
{
61+
type Locales = {
6262
[locale: string]: string | {
63-
[stringKey: string]: string;
64-
};
63+
[stringKey: string]: string
64+
}
6565
}
6666
```
6767
@@ -72,30 +72,36 @@ The key should be the locale name, and the value can either be _the path to the
7272
Using a JSON path has the advantage of automatically detecting changes across compilations, which is useful in development.
7373
7474
Example:
75-
```json5
76-
{
77-
en: './locales/en.json',
78-
es: './locales/es.json',
79-
...
80-
}
75+
```js
76+
new LocalizeAssetsPlugin({
77+
locales: {
78+
en: './locales/en.json',
79+
es: './locales/es.json'
80+
// ...
81+
}
82+
// ...
83+
})
8184
```
8285
8386
Or:
8487
85-
```json5
86-
{
87-
en: {
88-
helloWorld: 'Hello World!',
89-
goodbyeWorld: 'Goodbye World!',
90-
...
91-
},
92-
es: {
93-
helloWorld: '¡Hola Mundo!',
94-
goodbyeWorld: '¡Adiós Mundo!',
95-
...
96-
},
97-
...
98-
}
88+
```js
89+
new LocalizeAssetsPlugin({
90+
locales: {
91+
en: {
92+
helloWorld: 'Hello World!',
93+
goodbyeWorld: 'Goodbye World!'
94+
// ...
95+
},
96+
es: {
97+
helloWorld: '¡Hola Mundo!',
98+
goodbyeWorld: '¡Adiós Mundo!'
99+
// ...
100+
}
101+
// ...
102+
}
103+
// ...
104+
})
99105
```
100106
101107
#### functionName
@@ -106,7 +112,7 @@ Default: `__`
106112
The function name to use to detect localization string keys.
107113
108114
```js
109-
const message = __('helloWorld'); // => 'Hello world!'
115+
const message = __('helloWorld') // => 'Hello world!'
110116
```
111117
#### throwOnMissing
112118
Type: `boolean`
@@ -130,23 +136,23 @@ Enable to see warnings when unused string keys are found.
130136
### localizeCompiler
131137
Type:
132138
```ts
133-
Record<
134-
string, // localizer function name (eg. __)
135-
(
139+
type LocalizeCompiler = {
140+
// localizer function name (eg. __)
141+
[functionName: string]: (
136142
this: LocalizeCompilerContext,
137143
localizerArguments: string[],
138144
localeName: string,
139145
) => string
140-
>
146+
}
141147
```
142148
143149
Default:
144150
```ts
145-
{
151+
const localizeCompiler = {
146152
__(localizerArguments) {
147-
const [key] = localizerArguments;
148-
const keyResolved = this.resolveKey();
149-
return keyResolved ? JSON.stringify(keyResolved) : key;
153+
const [key] = localizerArguments
154+
const keyResolved = this.resolveKey()
155+
return keyResolved ? JSON.stringify(keyResolved) : key
150156
}
151157
}
152158
```

jest.config.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,35 @@
2222
"files": [
2323
"dist"
2424
],
25-
"main": "dist/index.js",
25+
"main": "./dist/index.cjs",
26+
"types": "./dist/index.d.ts",
27+
"imports": {
28+
"#webpack-localize-assets-plugin": {
29+
"types": "./src/index.d.ts",
30+
"development": "./src/index.ts",
31+
"default": "./dist/index.cjs"
32+
},
33+
"webpack": {
34+
"webpack5": "webpack5",
35+
"default": "webpack"
36+
},
37+
"webpack/*": {
38+
"webpack5": "webpack5/*",
39+
"default": "webpack/*"
40+
}
41+
},
2642
"scripts": {
43+
"prepare": "simple-git-hooks",
2744
"lint": "eslint .",
28-
"build": "tsc",
29-
"typecheck": "tsc --noEmit",
30-
"pretest": "npm run build",
31-
"test": "npm run test:wp4 && npm run test:wp5",
32-
"test:wp4": "jest",
33-
"test:wp5": "WEBPACK=5 jest"
45+
"build": "pkgroll --target node12.20 --minify",
46+
"type-check": "tsc --noEmit",
47+
"dev": "tsx watch --loader alias-imports -C development -C webpack5 tests",
48+
"test": "pnpm test:wp4 && pnpm test:wp5",
49+
"test:wp4": "tsx --loader alias-imports tests",
50+
"test:wp5": "tsx --loader alias-imports --conditions webpack5 tests"
3451
},
35-
"husky": {
36-
"hooks": {
37-
"pre-commit": "npm run build && lint-staged && npm test"
38-
}
52+
"simple-git-hooks": {
53+
"pre-commit": "pnpm build && pnpm lint-staged && pnpm test"
3954
},
4055
"lint-staged": {
4156
"*.{js,ts}": "eslint"
@@ -46,34 +61,42 @@
4661
"dependencies": {
4762
"@types/estree": "^0.0.50",
4863
"acorn": "^8.6.0",
49-
"astring": "^1.8.1",
64+
"astring": "^1.8.3",
5065
"has-own-prop": "^2.0.0",
51-
"magic-string": "^0.25.7",
66+
"magic-string": "^0.27.0",
5267
"source-map": "^0.7.3",
5368
"webpack-sources": "^2.2.0"
5469
},
5570
"devDependencies": {
56-
"@pvtnbr/eslint-config": "^0.6.1",
71+
"@pvtnbr/eslint-config": "^0.33.0",
5772
"@types/estree": "^0.0.50",
58-
"@types/jest": "^27.0.3",
5973
"@types/mini-css-extract-plugin": "^2.4.0",
6074
"@types/webpack": "^4.41.32",
6175
"@types/webpack-manifest-plugin": "^3.0.5",
76+
"@types/webpack-sources": "^3.2.0",
77+
"alias-imports": "^1.0.0",
6278
"css-loader": "^5.2.4",
63-
"es-jest": "^1.5.0",
64-
"eslint": "^7.32.0",
65-
"husky": "^4.3.8",
66-
"jest": "^27.3.1",
79+
"eslint": "^8.28.0",
6780
"lint-staged": "^12.1.2",
81+
"manten": "^0.6.0",
6882
"mini-css-extract-plugin": "^1.6.0",
83+
"pkgroll": "^1.5.0",
84+
"simple-git-hooks": "^2.8.0",
6985
"tempy": "^1.0.1",
70-
"typescript": "^4.5.2",
86+
"terser-webpack-plugin": "^5.3.6",
87+
"tsx": "^3.12.1",
88+
"typescript": "^4.9.3",
7189
"webpack": "4.42.0",
7290
"webpack-manifest-plugin": "^3.1.1",
73-
"webpack-test-utils": "^1.1.0",
91+
"webpack-test-utils": "^2.1.0",
7492
"webpack5": "npm:[email protected]"
7593
},
7694
"eslintConfig": {
7795
"extends": "@pvtnbr"
96+
},
97+
"pnpm": {
98+
"patchedDependencies": {
99+
100+
}
78101
}
79102
}

patches/[email protected]

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/package.json b/package.json
2+
index a37dc0a9959d745b2ef53e3c5432304580ac30aa..1a56d24a079924ab86c141fa8e91133be43689a6 100644
3+
--- a/package.json
4+
+++ b/package.json
5+
@@ -6,6 +6,7 @@
6+
"module": "./dist/astring.mjs",
7+
"types": "./astring.d.ts",
8+
"exports": {
9+
+ "types": "./astring.d.ts",
10+
"import": "./dist/astring.mjs",
11+
"require": "./dist/astring.js",
12+
"browser": "./dist/astring.min.js"

0 commit comments

Comments
 (0)