Skip to content

Commit 8acf03c

Browse files
committed
refactor: replace has-own-prop with local utility, remove unused deps
1 parent 77607ae commit 8acf03c

15 files changed

Lines changed: 35 additions & 59 deletions

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@
6262
"webpack": "^4.42.0 || ^5.10.0"
6363
},
6464
"devDependencies": {
65-
"@types/webpack": "^4.41.32",
66-
"@types/webpack-manifest-plugin": "^3.0.5",
65+
"@types/webpack": "^4.41.40",
6766
"@types/webpack-sources": "^3.2.0",
6867
"alias-imports": "^1.0.0",
6968
"clean-pkg-json": "^1.2.0",
7069
"css-loader": "^5.2.4",
71-
"has-own-prop": "^3.1.0",
7270
"lintroll": "^1.30.0",
7371
"manten": "^2.0.0",
7472
"mini-css-extract-plugin": "^1.6.0",

pnpm-lock.yaml

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/@types/webpack.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ declare module 'webpack/lib/WebpackError.js' {
2424
/* eslint-enable @typescript-eslint/no-explicit-any */
2525

2626
declare module 'mini-css-extract-plugin';
27+
declare module 'webpack-manifest-plugin';

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { stringifyAstNode } from './utils/stringify-ast-node.ts';
1010
import { handleSingleLocaleLocalization } from './single-locale.ts';
1111
import { handleMultiLocaleLocalization } from './multi-locale/index.ts';
1212
import { warnOnUnusedKeys } from './utils/warn-on-unused-keys.ts';
13-
14-
const name = 'webpack-localize-assets-plugin';
13+
import { name } from './plugin-name.ts';
1514

1615
const defaultLocalizerName = '__';
1716

src/multi-locale/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import {
1111
} from '../utils/on-localizer-call.ts';
1212
import { onAssetPath, onOptimizeAssets } from '../utils/webpack.ts';
1313
import { replaceLocaleInAssetName } from '../utils/localize-filename.ts';
14+
import { name } from '../plugin-name.ts';
1415
import { insertPlaceholderFunction } from './localizer-function.ts';
1516
import { generateLocalizedAssets } from './generate-localized-assets.ts';
1617
import { assetNamePlaceholder } from './asset-name.ts';
1718

18-
const name = 'webpack-localize-assets-plugin';
19-
2019
export const handleMultiLocaleLocalization = (
2120
compilation: WP5.Compilation,
2221
normalModuleFactory: NormalModuleFactory,

src/multi-locale/localizer-function.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import type {
1515
} from '../types-internal.ts';
1616
import { pushUniqueError } from '../utils/webpack.ts';
1717
import { callLocalizeCompiler } from '../utils/call-localize-compiler.ts';
18-
19-
const name = 'webpack-localize-assets-plugin';
18+
import { name } from '../plugin-name.ts';
2019

2120
const placeholderFunctionName = `_placeholder${sha256(name).slice(0, 8)}`;
2221

src/plugin-name.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const name = 'webpack-localize-assets-plugin';

src/types-internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type WP4 from 'webpack';
22
import type WP5 from 'webpack5';
3-
import hasOwnProp from 'has-own-prop';
3+
import { hasOwn } from './utils/has-own.ts';
44
import type {
55
LocaleName,
66
LocaleStrings,
@@ -20,7 +20,7 @@ export const validateOptions = <LocalizedData>(options: Options<LocalizedData>):
2020
throw new Error('locales must contain at least one locale');
2121
}
2222
if (options.sourceMapForLocales
23-
&& options.sourceMapForLocales.some(locale => !hasOwnProp(options.locales, locale))) {
23+
&& options.sourceMapForLocales.some(locale => !hasOwn(options.locales, locale))) {
2424
throw new Error('sourceMapForLocales must contain valid locales');
2525
}
2626
if (options.localizeCompiler) {

src/utils/has-own.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { hasOwnProperty } = Object.prototype;
2+
3+
export const hasOwn = (
4+
object: object,
5+
property: PropertyKey,
6+
) => hasOwnProperty.call(object, property);

src/utils/load-locale-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import path from 'path';
22
import type { readFileSync } from 'fs';
3-
import hasOwnProp from 'has-own-prop';
43
import type {
54
Compiler,
65
UnprocessedLocalesMap,
76
LocaleName,
87
LocalesMap,
98
LocaleFilePath,
109
} from '../types-internal.ts';
10+
import { hasOwn } from './has-own.ts';
1111

1212
type FSLike = {
1313
readFileSync: typeof readFileSync;
@@ -35,7 +35,7 @@ export const loadLocaleData = (
3535
const paths = new Set<LocaleFilePath>();
3636

3737
for (const localeName in unprocessedLocales) {
38-
if (!hasOwnProp(unprocessedLocales, localeName)) {
38+
if (!hasOwn(unprocessedLocales, localeName)) {
3939
continue;
4040
}
4141

0 commit comments

Comments
 (0)