Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/smooth-dots-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@devup-ui/webpack-plugin": patch
"@devup-ui/next-plugin": patch
"@devup-ui/vite-plugin": patch
---

Add include option
1 change: 1 addition & 0 deletions packages/next-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"typescript": "^5.7.3"
},
"peerDependencies": {
"@devup-ui/webpack-plugin": "*",
"next": "*"
}
}
3 changes: 2 additions & 1 deletion packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"typescript": "^5.7.3"
},
"peerDependencies": {
"vite": "*"
"vite": "*",
"@devup-ui/wasm": "*"
}
}
3 changes: 3 additions & 0 deletions packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"dependencies": {
"@devup-ui/wasm": "workspace:*"
},
"peerDependencies": {
"@devup-ui/wasm": "*"
},
"devDependencies": {
"vite": "^6.1.0",
"@types/webpack": "^5.28.5",
Expand Down
40 changes: 0 additions & 40 deletions packages/webpack-plugin/src/__tests__/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,6 @@ beforeEach(() => {
})

describe('devupUILoader', () => {
it('should ignore lib files', () => {
const t = {
getOptions: () => ({
package: 'package',
cssFile: 'cssFile',
watch: false,
}),
addDependency: vi.fn(),
async: vi.fn().mockReturnValue(vi.fn()),
resourcePath: 'node_modules/package/index.ts',
}
devupUILoader.bind(t as any)(
Buffer.from('code'),
'node_modules/package/index.ts',
)

expect(t.async).toHaveBeenCalled()
expect(t.async()).toHaveBeenCalledWith(null, Buffer.from('code'))
})

it('should ignore wrong files', () => {
const t = {
getOptions: () => ({
package: 'package',
cssFile: 'cssFile',
watch: false,
}),
async: vi.fn().mockReturnValue(vi.fn()),
resourcePath: 'node_modules/package/index.css',
addDependency: vi.fn(),
}
devupUILoader.bind(t as any)(
Buffer.from('code'),
'node_modules/package/index.css',
)

expect(t.async).toHaveBeenCalled()
expect(t.async()).toHaveBeenCalledWith(null, Buffer.from('code'))
})

it('should extract code with css', async () => {
const _compiler = {
__DEVUP_CACHE: '',
Expand Down
38 changes: 38 additions & 0 deletions packages/webpack-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('devupUIPlugin', () => {
it('should apply default options', () => {
import.meta.resolve = vi.fn().mockReturnValue('resolved')
expect(new DevupUIWebpackPlugin({}).options).toEqual({
include: [],
package: '@devup-ui/react',
cssFile: resolve('.df', 'devup-ui.css'),
devupPath: 'devup.json',
Expand All @@ -48,6 +49,7 @@ describe('devupUIPlugin', () => {
watch: false,
}).options,
).toEqual({
include: [],
package: 'new-package',
cssFile: 'new-css-file',
devupPath: 'new-devup-path',
Expand Down Expand Up @@ -265,4 +267,40 @@ describe('devupUIPlugin', () => {
)
})
})

it('should include lib', () => {
vi.mocked(readFileSync).mockReturnValue('{"theme": "theme"}')
vi.mocked(getThemeInterface).mockReturnValue('interfaceCode')
vi.mocked(getCss).mockReturnValue('css')
vi.mocked(writeFileSync).mockReturnValue()
vi.mocked(mkdirSync)

const plugin = new DevupUIWebpackPlugin({
include: ['lib'],
})
const compiler = {
options: {
module: {
rules: [],
},
},
hooks: {
afterCompile: {
tap: vi.fn(),
},
watchRun: {
tapAsync: vi.fn(),
},
},
} as any
plugin.apply(compiler)

expect(writeFileSync).toHaveBeenCalledWith(
resolve('.df', 'devup-ui.css'),
'',
{
encoding: 'utf-8',
},
)
})
})
8 changes: 0 additions & 8 deletions packages/webpack-plugin/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ const devupUILoader: RawLoaderDefinitionFunction<DevupUILoaderOptions> =
} = this.getOptions()
const callback = this.async()
const id = this.resourcePath
if (
id.includes('node_modules/') ||
id.includes('@devup-ui/react') ||
!/\.[tj](s|sx)?$/.test(id)
) {
callback(null, source)
return
}

try {
const { code, css } = codeExtract(
Expand Down
9 changes: 8 additions & 1 deletion packages/webpack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface DevupUIWebpackPluginOptions {
interfacePath: string
watch: boolean
debug: boolean
include: string[]
}

export class DevupUIWebpackPlugin {
Expand All @@ -36,6 +37,7 @@ export class DevupUIWebpackPlugin {
cssFile = resolve(interfacePath, 'devup-ui.css'),
watch = false,
debug = false,
include = [],
}: Partial<DevupUIWebpackPluginOptions> = {}) {
this.options = {
package: libPackage,
Expand All @@ -44,6 +46,7 @@ export class DevupUIWebpackPlugin {
interfacePath,
watch,
debug,
include,
}
}

Expand Down Expand Up @@ -132,7 +135,11 @@ export class DevupUIWebpackPlugin {
compiler.options.module.rules.push(
{
test: /\.(tsx|ts|js|mjs|jsx)$/,
exclude: /node_modules/,
exclude: new RegExp(
this.options.include.length
? `node_modules(?!(.*${this.options.include.join('|').replaceAll('/', '[\\/\\\\]')})([\\/\\\\]|$))`
: 'node_modules',
),
enforce: 'pre',
use: [
{
Expand Down