Skip to content

Commit

Permalink
Merge pull request #19 from abxvn/feat/upgrade-packages
Browse files Browse the repository at this point in the history
Feat/upgrade packages
  • Loading branch information
hungluu authored Dec 26, 2023
2 parents 5893101 + c91b21e commit 3cc619d
Show file tree
Hide file tree
Showing 47 changed files with 925 additions and 632 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
"start": "webpack",
"build": "webpack --node-env production",
"components": "webpack -c webpack.components.config.js",
"test": "jest",
"lint": "eslint \"packages/**/*.{ts,tsx}\" -c .eslintrc.js",
"test": "jest -c tests/spec/config.js",
"lint": "eslint packages --ext ts",
"resolve": "yarn workspace @abux/resolve",
"builder": "yarn workspace @abux/builder"
},
"dependencies": {
"@abux/webpack-dts": "workspace:^",
"@changesets/cli": "^2.26.1",
"typescript": "^5.0.4",
"typescript": "~5.0.4",
"webpack": "^5.80.0"
},
"devDependencies": {
"@types/fs-extra": "^11.0.1",
"@types/jest": "^29.5.1",
"@types/node": "^20.3.3",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"eslint": "^8.39.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @abux/builder

## 0.3.4

### Patch Changes

- Move dts plugins into packages
- Updated dependencies
- @abux/webpack-dts@0.0.1

## 0.3.3

### Patch Changes
Expand Down
16 changes: 16 additions & 0 deletions packages/builder/config/_tests/spec/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { resolve } = require('path')

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
rootDir: resolve(__dirname, '../..'),
setupFilesAfterEnv: [
'<rootDir>/tests/spec/setup.js'
],
testRegex: '.+/*\\.spec\\.(ts|tsx)$',
preset: 'ts-jest',
transform: {
'^.+\\.tsx?$': [
'ts-jest'
]
}
}
6 changes: 6 additions & 0 deletions packages/builder/config/_tests/spec/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (typeof global.setImmediate === 'undefined') {
Object.assign(global, {
setImmediate: setTimeout,
clearImmediate: clearTimeout
})
}
62 changes: 0 additions & 62 deletions packages/builder/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,6 @@
declare module '@abux/builder/cli/index' {
export type { IFilter, IBuilderCustomOptions } from '@abux/builder/src/interfaces';
}
declare module '@abux/builder/src/plugins/DtsPlugin' {
import type { Compiler } from 'webpack';
import type { IPathResolver } from '@abux/builder/src/interfaces';
export class DtsPlugin {
readonly path: IPathResolver;
constructor (rootPath: string);
apply (compiler: Compiler): void;
}
}
declare module '@abux/builder/src/lib/dts' {
/// <reference types="node" />
import type { CompilerOptions } from 'typescript';
import EventEmitter from 'events';
import { type IPathResolver } from '@abux/builder/src/interfaces';
interface IGenerateOptions {
name: string;
inputDir: string;
main?: string;
projectPath?: string;
outputPath?: string;
files?: string[];
references?: string[];
filePatterns?: string[];
}
export class Dts extends EventEmitter {
generate ({ name, main, inputDir, projectPath, outputPath, files, references, filePatterns }: IGenerateOptions): Promise<void>;
}
interface IDtsWriterOptions {
name: string;
main?: string;
outputPath: string;
references?: string[];
excludedPatterns?: string[];
resolvedModule?: (resolution: IModuleResolution) => string;
resolvedImport?: (resolution: IModuleImportResolution) => string;
}
interface IModuleResolution {
currentModule: string;
}
interface IModuleImportResolution {
currentModule: string;
importedModule: string;
isExternal?: boolean;
}
export class DtsWriter extends EventEmitter {
readonly ident = " ";
readonly options: IDtsWriterOptions;
constructor (options: IDtsWriterOptions);
write (inputDir: string, compilerOptions: CompilerOptions, filePaths: string[]): Promise<void>;
}
interface IDtsFilters {
filePatterns?: string[];
}
export class DtsFilterWriter extends DtsWriter {
readonly filters: IDtsFilters;
readonly modulePathMap: Record<string, string>;
readonly moduleDepsMap: Record<string, string[]>;
readonly cachedOutputs: Record<string, string>;
constructor (options: IDtsWriterOptions, filters: IDtsFilters);
emitOutput (): void;
}
}
declare module '@abux/builder/src/interfaces' {
import type { Configuration, WebpackPluginInstance, WebpackOptionsNormalized, ExternalsPlugin } from 'webpack';
export type IBuildEnvironment = 'development' | 'production';
Expand Down
5 changes: 3 additions & 2 deletions packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abux/builder",
"version": "0.3.3",
"version": "0.3.4",
"description": "Quick scaffolding code base to build web apps and games",
"license": "MIT",
"main": "./cli/index.js",
Expand Down Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@abux/logger": "workspace:^",
"@abux/resolve": "workspace:^",
"@abux/webpack-dts": "workspace:^",
"commander": "^10.0.1",
"dotenv": "^16.0.3",
"execa": "^5.1.1",
Expand All @@ -41,7 +42,7 @@
"kind-of": "^6.0.3",
"minimatch": "^9.0.0",
"ts-loader": "^9.4.2",
"typescript": "^5.0.2",
"typescript": "~5.0.2",
"webpack": "^5.76.3",
"webpack-dev-server": "^4.13.3",
"webpack-node-externals": "^3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/cmd/init/copyConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const copyConfigs = async ({ answers, deps, editor }: ICopyConfigsParams)
!hasPackagesFolder ? 'packages/dummy/cli/_index.ts' : '',
'_.yarnrc.yml',
deps.requires('typescript') ? '_tsconfig.json' : '',
deps.requires('jest') ? '_jest.config.js' : '',
deps.requires('jest') ? '_tests' : '',
deps.requires('eslint') ? '_.eslintrc.js' : ''
].filter(Boolean)

Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/cmd/init/updatePackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export const updatePackageJson = async ({ modify = true, deps, editor }: IUpdate

if (useEslint) {
info(`Essential config for linting command:
${italic('"lint": "eslint packages/**/*.ts"')}`)
${italic('"lint": "eslint packages --ext ts"')}`)
}

if (useJest) {
info(`Essential config for testing command:
${italic('"test": "jest"')}`)
${italic('"test": "jest -c tests/spec/config.js"')}`)
}

return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type IWebpackConfigs } from '../interfaces'
import { getMockConfig } from '../../tests/mocks/mockConfigs'
import { DtsPlugin } from '../plugins/DtsPlugin'
import { WebpackDtsPlugin } from '@abux/webpack-dts'
import generateDts from './generateDts'

describe('generateDts#configs', () => {
Expand All @@ -16,7 +16,7 @@ describe('generateDts#configs', () => {
const devPlugins = devConfigs[0].plugins || []
const prodPlugins = prodConfigs[0].plugins || []

expect(devPlugins.some(p => p instanceof DtsPlugin)).toBe(false)
expect(prodPlugins.some(p => p instanceof DtsPlugin)).toBe(true)
expect(devPlugins.some(p => p instanceof WebpackDtsPlugin)).toBe(false)
expect(prodPlugins.some(p => p instanceof WebpackDtsPlugin)).toBe(true)
})
})
4 changes: 2 additions & 2 deletions packages/builder/src/filters/generateDts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { map } from '../lib/data'
import type { IFilter } from '../interfaces'
import { DtsPlugin } from '@abux/builder/src/plugins/DtsPlugin/index.js'
import { WebpackDtsPlugin } from '@abux/webpack-dts'

const generateDts: IFilter = async ({ editor }) => {
return {
configs: await map(editor.configs, async config => ({
...config,
plugins: [
...config.plugins,
editor.options.envName === 'production' && new DtsPlugin(editor.path.rootPath)
editor.options.envName === 'production' && new WebpackDtsPlugin(editor.path.rootPath)
]
}))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { type IWebpackConfigs } from '../interfaces'
import { extractPattern } from '../lib/data'
import { getMockConfig } from '../../tests/mocks/mockConfigs'
import { resolveOptions } from '../lib/entries'

jest.mock('../lib/entries', () => {
return {
...jest.requireActual('../lib/entries'),
resolveOptions: jest.fn().mockImplementation((p, o) => o(p))
}
})
const mockLibEntries = {
resolveOptions
}

const webEntries = {
'web/index.ts': {
Expand Down
Loading

0 comments on commit 3cc619d

Please sign in to comment.