Skip to content

Commit 04bfc23

Browse files
committed
minor patches
1 parent c59447b commit 04bfc23

File tree

8 files changed

+52
-12
lines changed

8 files changed

+52
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"node": ">= 12.22.1"
88
},
99
"scripts": {
10-
"build": "tsc && cp ./src/cjs.js ./lib",
10+
"build": "tsc",
1111
"lint": "eslint",
1212
"test:clean": "find test/**/build/ -name '*.jpg' -o -name '*.png' -o -name '*.avif' -o -name '*.webp' -o -name '*.jpeg' -o -name '*.js' | xargs rm -f",
1313
"test": "npm run build && npm run test:clean && webpack --config=./test/jimp/webpack.config.js && webpack --config=./test/sharp/webpack.config.js && jest"

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export default function loader(this: LoaderContext<Options>, content: string): v
122122
placeholderSize,
123123
mime,
124124
sizes,
125-
esModule: options.esModule,
126125
}
127126
orchestrate({ cacheOptions, transformParams })
128127
.then((result) => loaderCallback(null, result))
@@ -147,7 +146,7 @@ async function orchestrate(params: OrchestrateParams) {
147146
}
148147

149148
// Transform based on the parameters
150-
export async function transform({
149+
async function transform({
151150
adapterModule,
152151
resourcePath,
153152
createFile,
@@ -156,7 +155,6 @@ export async function transform({
156155
outputPlaceholder,
157156
placeholderSize,
158157
adapterOptions,
159-
esModule,
160158
}: TransformParams): Promise<string> {
161159
const adapter: Adapter = adapterModule || require('./adapters/sharp')
162160
const img = adapter(resourcePath)
@@ -177,7 +175,7 @@ export async function transform({
177175
// default to the biggest image
178176
const defaultImage = files[files.length - 1]
179177

180-
return `${esModule ? 'export default' : 'module.exports ='} {
178+
return `${adapterOptions.esModule ? 'export default' : 'module.exports ='} {
181179
srcSet: ${srcset},
182180
images: [${images}],
183181
src: ${defaultImage.path},

src/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,5 @@ export interface TransformParams {
5959
placeholderSize: number
6060
mime: MimeType
6161
sizes: number[]
62-
esModule: boolean
6362
adapterOptions: Options & ImageOptions
6463
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const getOutputAndPublicPath: GetOutputAndPublicPath = (
146146
if (typeof configOutputPath === 'function') {
147147
outputPath = configOutputPath(fileName)
148148
} else {
149-
outputPath = path.posix.join(configOutputPath, fileName)
149+
outputPath = path.join(configOutputPath, fileName)
150150
}
151151
}
152152
let publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`
@@ -155,7 +155,7 @@ const getOutputAndPublicPath: GetOutputAndPublicPath = (
155155
if (typeof configPublicPath === 'function') {
156156
publicPath = configPublicPath(fileName)
157157
} else {
158-
publicPath = path.posix.join(configPublicPath, fileName)
158+
publicPath = path.join(configPublicPath, fileName)
159159
}
160160
publicPath = JSON.stringify(publicPath)
161161
}

test/jimp/build/__snapshots__/test.js.snap

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,35 @@ Object {
310310
}
311311
`;
312312

313+
exports[`public path should replace global publicPath absolute 1`] = `
314+
Object {
315+
"default": Object {
316+
"height": 900,
317+
"images": Array [
318+
Object {
319+
"height": 450,
320+
"path": "/public/c869fe04ebafd01d-500.jpg",
321+
"width": 500,
322+
},
323+
Object {
324+
"height": 675,
325+
"path": "/public/76a7b8dd076af418-750.jpg",
326+
"width": 750,
327+
},
328+
Object {
329+
"height": 900,
330+
"path": "/public/076d6ca8665b1d94-1000.jpg",
331+
"width": 1000,
332+
},
333+
],
334+
"src": "/public/076d6ca8665b1d94-1000.jpg",
335+
"srcSet": "/public/c869fe04ebafd01d-500.jpg 500w,/public/76a7b8dd076af418-750.jpg 750w,/public/076d6ca8665b1d94-1000.jpg 1000w",
336+
"toString": [Function],
337+
"width": 1000,
338+
},
339+
}
340+
`;
341+
313342
exports[`single size 1`] = `
314343
Object {
315344
"default": Object {

test/jimp/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ test('public path should replace global publicPath', () => {
3838
const multi = require('../cat-1000.jpg?outputPath=img/&publicPath=public/')
3939
expect(multi).toMatchSnapshot()
4040
})
41+
test('public path should replace global publicPath absolute', () => {
42+
const multi = require('../cat-1000.jpg?outputPath=/img2/&publicPath=/public/')
43+
expect(multi).toMatchSnapshot()
44+
})
4145

4246
test('with placeholder image', () => {
4347
const output = require('../cat-1000.jpg?placeholder=true')

test/utils.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { getOutputAndPublicPath } from '../lib/utils'
22

33
describe('Utils package', () => {
4-
it('should create both paths', () => {
4+
it('should create both paths respecting absolutes', () => {
55
const { outputPath, publicPath } = getOutputAndPublicPath('file.png', {
66
outputPath: '/dist/img/',
7-
publicPath: '/img',
7+
publicPath: '/public',
88
})
99
expect(outputPath).toBe('/dist/img/file.png')
10-
expect(publicPath).toBe('"/img/file.png"')
10+
expect(publicPath).toBe('"/public/file.png"')
11+
})
12+
13+
it('should create both paths ', () => {
14+
const { outputPath, publicPath } = getOutputAndPublicPath('file.png', {
15+
outputPath: 'dist/img/',
16+
publicPath: 'public/',
17+
})
18+
expect(outputPath).toBe('dist/img/file.png')
19+
expect(publicPath).toBe('"public/file.png"')
1120
})
1221
})

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"lib": ["es2018"],
77
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
88
"outDir": "lib",
9+
"allowJs": true,
910
/* Strict Type-Checking Options */
1011
"strict": true /* Enable all strict type-checking options. */,
1112
"moduleResolution": "node",
@@ -14,5 +15,5 @@
1415
/* Additional Checks */
1516
"resolveJsonModule": true
1617
},
17-
"include": ["src/**/*.ts"],
18+
"include": ["src/**/*"],
1819
}

0 commit comments

Comments
 (0)