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
5 changes: 5 additions & 0 deletions .changeset/many-mirrors-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/webpack-plugin": patch
---

Fix watch logic
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
8 changes: 8 additions & 0 deletions packages/webpack-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ describe('devupUIPlugin', () => {
rules: [],
},
},
hooks: {
afterCompile: {
tap: vi.fn(),
},
watchRun: {
tapAsync: vi.fn(),
},
},
} as any)

expect(writeFileSync).toHaveBeenCalledWith('css', '', {
Expand Down
43 changes: 21 additions & 22 deletions packages/webpack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,38 @@ export class DevupUIWebpackPlugin {

apply(compiler: Compiler) {
// read devup.json
if (existsSync(this.options.devupPath)) {
const existsDevup = existsSync(this.options.devupPath)
if (existsDevup) {
try {
this.writeDataFiles()
} catch (error) {
console.error(error)
}

let lastModifiedTime: number | null = null

compiler.hooks.afterCompile.tap('DevupUIWebpackPlugin', (compilation) => {
compilation.fileDependencies.add(this.options.devupPath)
this.watch = true
})
compiler.hooks.watchRun.tapAsync(
'DevupUIWebpackPlugin',
(_, callback) => {
stat(this.options.devupPath, (err, stats) => {
if (err) {
console.error(`Error checking ${this.options.devupPath}:`, err)
return callback()
}
}

const modifiedTime = stats.mtimeMs
if (lastModifiedTime && lastModifiedTime !== modifiedTime) {
this.writeDataFiles()
}
let lastModifiedTime: number | null = null
compiler.hooks.watchRun.tapAsync('DevupUIWebpackPlugin', (_, callback) => {
this.watch = true
if (existsDevup)
stat(this.options.devupPath, (err, stats) => {
if (err) {
console.error(`Error checking ${this.options.devupPath}:`, err)
return callback()
}

lastModifiedTime = modifiedTime
callback()
})
},
)
}
const modifiedTime = stats.mtimeMs
if (lastModifiedTime && lastModifiedTime !== modifiedTime) {
this.writeDataFiles()
}

lastModifiedTime = modifiedTime
callback()
})
})
// Create an empty CSS file
if (!existsSync(this.options.cssFile)) {
writeFileSync(this.options.cssFile, '', { encoding: 'utf-8' })
Expand Down
Loading