Skip to content

Commit

Permalink
chore: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Sep 24, 2023
1 parent 5403b81 commit e3cc911
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 1 addition & 4 deletions scripts/buildFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ async function run() {

console.log(c.red(c.inverse(c.bold('\n Rollup '))), name, '\n')
execSync('npx rollup --version', { cwd: path, stdio: 'inherit' })
execSync('npx rollup --bundleConfigAsCjs -c', {
cwd: path,
stdio: 'inherit',
})
execSync('npx rollup --bundleConfigAsCjs -c', { cwd: path, stdio: 'inherit' })

console.log(c.blue(c.inverse(c.bold('\n Webpack '))), name, '\n')
execSync('npx webpack --version', { cwd: path, stdio: 'inherit' })
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/load/unplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ module.exports = createUnplugin((options) => {
loadInclude(id) {
return targetFileReg.test(id)
},
async load(id) {
load(id) {
const code = fs.readFileSync(id, { encoding: 'utf-8' })
const str = new MagicString(code)
const _index = code.indexOf('msg')
const loadInjectedCode = 'msg -> through the load hook -> __unplugin__'

str.overwrite(_index, _index + 'msg'.length, loadInjectedCode)
return str.toString()
},
Expand All @@ -25,6 +26,7 @@ module.exports = createUnplugin((options) => {
const index = code.indexOf('__unplugin__')
if (index === -1)
return null

const injectedCode = `transform-[Injected ${options.msg}]`

if (code.includes(injectedCode))
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/transform/unplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ module.exports = createUnplugin((options, meta) => {
return null

const injectedCode = `[Injected ${options.msg}]`

if (id.includes(injectedCode))
throw new Error('File was already transformed')

s.overwrite(index, index + '__UNPLUGIN__'.length, injectedCode)

return {
code: s.toString(),
map: s.generateMap({
Expand Down

0 comments on commit e3cc911

Please sign in to comment.