Skip to content

Commit

Permalink
Merge pull request #134 from madtisa/f/support-bundling-on-windows
Browse files Browse the repository at this point in the history
Support bundling on windows
  • Loading branch information
simoneb committed Nov 1, 2023
2 parents 5bfb553 + 2ab8805 commit 9048a2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -20,7 +21,7 @@ jobs:
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ hashFiles('package.json') }}
key: node-modules-${{ matrix.os }}-${{ hashFiles('package.json') }}
- name: Install dependencies
run: npm install
- name: Run Tests
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const webpack = require('webpack')
const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency')
const { createFsFromVolume, Volume } = require('memfs')
const { sep, dirname, relative } = require('path')
const { join, dirname, relative } = require('path')
// const { cache } = require('webpack') // Cache handling missing

const fileBanner = `/* Start of pino-webpack-plugin additions */
Expand All @@ -25,6 +25,10 @@ const PLUGIN_NAME = 'PinoWebpackPlugin'

const fs = createFsFromVolume(new Volume())

function quote(path) {
return `'${path.replace(/([\\'])/g, '\\$1')}'`
}

class PinoWebpackPlugin {
constructor(options) {
options = { transports: [], ...options }
Expand Down Expand Up @@ -164,7 +168,7 @@ class PinoWebpackPlugin {
fileBanner,
'\n',
`globalThis.__bundlerPathsOverrides = {${dependenciesFiles.map(
([workerId, file]) => `'${workerId}': pinoWebpackAbsolutePath('${relativePath}${sep}${file}')`
([workerId, file]) => `'${workerId}': pinoWebpackAbsolutePath(${quote(join(relativePath, file))})`
)}};`,
'\n',
'/* End of pino-webpack-plugin additions */',
Expand Down
16 changes: 10 additions & 6 deletions test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ function createTests(tapInstance, webpackConfig, distFolder) {
const fileContent = readFileSync(resolve(distFolder, filePath), 'utf-8')
// Test if the file starts with the expected banner
tapInstance.ok(fileContent.startsWith(banner), `${basename(filePath)} should starts with banner`)
const quoteRegex = (path) => `'${path.replace(/\\/g, '\\\\\\\\')}'`
for (const dependencyKey in dependencies) {
// For each dependency, test if the expeted file is in the __bundlerPathsOverrides object
// For each dependency, test if the expected file is in the __bundlerPathsOverrides object
const dependencyRegexp = new RegExp(
`globalThis\\.__bundlerPathsOverrides = \\{.*?'${dependencyKey}': pinoWebpackAbsolutePath\\('${
(relative(dirname(filePath), dirname(dependencies[dependencyKey])) || '.') +
'/' +
dependencies[dependencyKey]
}'\\).*?\\}`
`globalThis\\.__bundlerPathsOverrides = \\{.*?'${dependencyKey}': pinoWebpackAbsolutePath\\(${
quoteRegex(
join(
relative(dirname(filePath), dirname(dependencies[dependencyKey])),
dependencies[dependencyKey]
)
)
}\\).*?\\}`
)
tapInstance.ok(fileContent.match(dependencyRegexp), `${dependencyKey} should have correct path in ${filePath}`)
}
Expand Down

0 comments on commit 9048a2e

Please sign in to comment.