diff --git a/package-lock.json b/package-lock.json index 16a5de14a6..133588885f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "workspaces": [ "packages/cli", "packages/cli-utils", + "packages/core", "packages/gatsby-plugin", "packages/html-templates", "packages/next-plugin", @@ -3083,6 +3084,10 @@ "resolved": "packages/cli-utils", "link": true }, + "node_modules/@bundle-stats/core": { + "resolved": "packages/core", + "link": true + }, "node_modules/@bundle-stats/html-templates": { "resolved": "packages/html-templates", "link": true @@ -42149,6 +42154,13 @@ "node": ">= 16.0" } }, + "packages/core": { + "version": "4.4.0", + "license": "MIT", + "engines": { + "node": ">= 16.0" + } + }, "packages/gatsby-plugin": { "name": "gatsby-plugin-bundle-stats", "version": "4.4.0", @@ -44411,6 +44423,9 @@ "typescript": "5.1.3" } }, + "@bundle-stats/core": { + "version": "file:packages/core" + }, "@bundle-stats/html-templates": { "version": "file:packages/html-templates", "requires": { diff --git a/package.json b/package.json index 3c23c94fb3..d34fafb777 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "workspaces": [ "packages/cli", "packages/cli-utils", + "packages/core", "packages/gatsby-plugin", "packages/html-templates", "packages/next-plugin", diff --git a/packages/core/.eslintignore b/packages/core/.eslintignore new file mode 100644 index 0000000000..183a6839bb --- /dev/null +++ b/packages/core/.eslintignore @@ -0,0 +1,5 @@ +node_modules +lib +lib-esm +types +!**/.*.js diff --git a/packages/core/.eslintrc.js b/packages/core/.eslintrc.js new file mode 100644 index 0000000000..9779f4e0f2 --- /dev/null +++ b/packages/core/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + rules: { + 'import/no-cycle': ['warn', { maxDepth: 1 }], + 'object-curly-newline': 'off', + 'function-paren-newline': 'off', + }, +}; diff --git a/packages/core/.gitignore b/packages/core/.gitignore new file mode 100644 index 0000000000..05d435296a --- /dev/null +++ b/packages/core/.gitignore @@ -0,0 +1,12 @@ +node_modules/ +.DS_Store +Thumbs.db +.idea/ +.vscode/ +*.sublime-project +*.sublime-workspace +*.log +yarn.lock +lib +lib-esm +types diff --git a/packages/core/.npmignore b/packages/core/.npmignore new file mode 100644 index 0000000000..bf3cf0fe94 --- /dev/null +++ b/packages/core/.npmignore @@ -0,0 +1,10 @@ +node_modules +**/__tests__ +__fixtures__ +.editorconfig +.eslintignore +.eslintrc.js +jsconfig.json +jest.config.js +jest.global.js +tsconfig.* diff --git a/packages/core/README.md b/packages/core/README.md new file mode 100644 index 0000000000..fddf3820f7 --- /dev/null +++ b/packages/core/README.md @@ -0,0 +1 @@ +# @bundle-stats/core diff --git a/packages/core/jest.config.js b/packages/core/jest.config.js new file mode 100644 index 0000000000..d21017f9ee --- /dev/null +++ b/packages/core/jest.config.js @@ -0,0 +1,5 @@ +module.exports = { + preset: 'ts-jest/presets/js-with-ts', + testEnvironment: 'node', + testPathIgnorePatterns: ['/__fixtures__/', '/node_modules/', '/lib/', '/lib-esm/', '/types/'], +}; diff --git a/packages/core/package.json b/packages/core/package.json new file mode 100644 index 0000000000..2dc21ceb18 --- /dev/null +++ b/packages/core/package.json @@ -0,0 +1,37 @@ +{ + "name": "@bundle-stats/core", + "version": "4.4.0", + "description": "BundleStats core functionality", + "main": "lib/index.js", + "module": "lib-esm/index.js", + "types": "types/index.d.ts", + "sideEffects": false, + "engines": { + "node": ">= 16.0" + }, + "directories": { + "lib": "lib" + }, + "scripts": { + "build": "npm run build-lib && npm run build-esm", + "build-lib": "rm -fr ./lib && npx tsc --rootDir ./src --project tsconfig.lib.json --outDir ./lib", + "build-esm": "rm -fr ./lib-esm && rm -fr ./types && npx tsc --rootDir ./src --project tsconfig.esm.json --outDir ./lib-esm", + "lint": "npx eslint . --ext .js,.ts --resolve-plugins-relative-to ../../", + "test": "jest" + }, + "keywords": [], + "author": { + "name": "Viorel Cojocaru", + "email": "vio@beanon.com", + "url": "https://beanon.com" + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/relative-ci/bundle-stats.git" + }, + "bugs": { + "url": "https://github.com/relative-ci/bundle-stats/issues" + }, + "homepage": "https://github.com/relative-ci/bundle-stats/blob/master/packages/core#readme" +} diff --git a/packages/core/src/index.test.ts b/packages/core/src/index.test.ts new file mode 100644 index 0000000000..af473f42ca --- /dev/null +++ b/packages/core/src/index.test.ts @@ -0,0 +1,33 @@ +import filter from './index'; + +/* eslint-disable import/no-relative-packages */ +import webpackStats from '../../utils/__fixtures__/webpack-stats-1'; +import webpackStatsExtracted from '../../utils/__fixtures__/webpack-stats-1.extracted'; +import webpackStatsConcatenatedModules from '../../utils/__fixtures__/webpack-stats-3'; +import webpackStatsConcatenatedModulesExtracted from '../../utils/__fixtures__/webpack-stats-3.extracted'; +/* eslint-enable import/no-relative-packages */ + +describe('Webpack filter', () => { + test('should return empty meta', () => { + const actual = filter({ + ...webpackStats, + builtAt: undefined, + hash: undefined, + } as any); + expect({ + ...webpackStatsExtracted, + builtAt: undefined, + hash: undefined, + }).toEqual(actual); + }); + + test('should return meta', () => { + const actual = filter(webpackStats as any); + expect(actual).toEqual(webpackStatsExtracted); + }); + + test('should filter concatenated modules', () => { + const actual = filter(webpackStatsConcatenatedModules as any); + expect(actual).toEqual(webpackStatsConcatenatedModulesExtracted); + }); +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/tsconfig.esm.json b/packages/core/tsconfig.esm.json new file mode 100644 index 0000000000..5a3c40e41e --- /dev/null +++ b/packages/core/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "ES2019", + "module": "ES6", + "declaration": true, + "declarationDir": "./types", + "noEmit": false + }, + "exclude": ["**/*.test.ts"] +} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json new file mode 100644 index 0000000000..52d43eaaa9 --- /dev/null +++ b/packages/core/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/core/tsconfig.lib.json b/packages/core/tsconfig.lib.json new file mode 100644 index 0000000000..ef05bcae8d --- /dev/null +++ b/packages/core/tsconfig.lib.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false + }, + "exclude": ["**/*.test.ts"] +}