Skip to content

Commit d22269d

Browse files
authored
fix: make "resolve" external, fixes pnp (#165)
* fixes #163
1 parent 7c13ff4 commit d22269d

10 files changed

Lines changed: 856 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
run: yarn install
3030
- name: Run Tests
3131
run: yarn test
32+
- name: Run yarn pnp tests
33+
if: matrix.os == 'ubuntu-latest'
34+
run: yarn test-pnp
3235
- name: Coverage
3336
if: matrix.os == 'ubuntu-latest'
3437
run: yarn test-coverage

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
"license": "MIT",
77
"main": "./dist/index.js",
88
"scripts": {
9-
"build": "ncc build src/asset-relocator.js",
9+
"build": "ncc build src/asset-relocator.js -e resolve",
1010
"codecov": "codecov",
1111
"test": "npm run build && jest",
12+
"test-pnp": "yarn pack -f test/yarn-pnp/assets-plugin-tarball.tgz && cd test/yarn-pnp && echo '' > yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && yarn run build && yarn run test",
1213
"test-coverage": "jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov"
1314
},
1415
"files": [
1516
"dist/*"
1617
],
18+
"dependencies": {
19+
"resolve": "^1.10.0"
20+
},
1721
"devDependencies": {
1822
"@vercel/ncc": "^0.25.1",
1923
"acorn": "^8.3.0",
@@ -31,7 +35,6 @@
3135
"memory-fs": "^0.4.1",
3236
"node-gyp-build": "^4.2.1",
3337
"node-pre-gyp": "^0.12.0",
34-
"resolve": "^1.10.0",
3538
"resolve-from": "3.0.0",
3639
"rollup-pluginutils": "^2.8.2",
3740
"semantic-release": "^17.3.0",

src/asset-relocator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getPackageScope = require('./utils/get-package-scope');
1414
const { pregyp, nbind } = require('./utils/binary-locators');
1515
const handleSpecialCases = require('./utils/special-cases');
1616
const { getOptions } = require("loader-utils");
17-
const resolve = require('resolve');
17+
const resolve = require('resolve'); //resolve should be external to be patched by yarn
1818
const mergeSourceMaps = require('./utils/merge-source-maps');
1919
const os = require('os');
2020
const nodeGypBuild = require('node-gyp-build');

test/yarn-pnp/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.yarn/cache
2+
/.yarn/install-state.gz
3+
/.yarn/unplugged
4+
/yarn.lock
5+
/.pnp.*
6+
/assets-plugin-tarball.tgz

test/yarn-pnp/.yarn/releases/yarn-3.2.1.cjs

Lines changed: 786 additions & 0 deletions
Large diffs are not rendered by default.

test/yarn-pnp/.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarnPath: .yarn/releases/yarn-3.2.1.cjs

test/yarn-pnp/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
sumPath: require.resolve('lodash/sum')
3+
}

test/yarn-pnp/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"build": "rm -rf dist && webpack",
5+
"test": "node test.js"
6+
},
7+
"dependencies": {
8+
"lodash": "^4.0.0"
9+
},
10+
"devDependencies": {
11+
"@vercel/webpack-asset-relocator-loader": "file:./assets-plugin-tarball.tgz",
12+
"webpack": "^5",
13+
"webpack-cli": "^4"
14+
},
15+
"packageManager": "yarn@3.2.1"
16+
}

test/yarn-pnp/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
const assert = require('assert');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const sumFilePath = path.resolve(__dirname, './dist/assets/sum.js');
7+
8+
9+
assert.equal(fs.existsSync(sumFilePath), true)
10+
assert.equal(require('./dist/main').sumPath, sumFilePath)
11+
12+
console.log('pnp test succeed!')

test/yarn-pnp/webpack.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
target: 'node',
3+
mode: 'production',
4+
entry: {
5+
main: './main.js'
6+
},
7+
output: {
8+
path: __dirname + '/dist',
9+
libraryTarget: 'commonjs'
10+
},
11+
module: {
12+
rules: [{
13+
test: /\.m?js$/,
14+
parser: { amd: false },
15+
use: {
16+
loader: require.resolve('@vercel/webpack-asset-relocator-loader'),
17+
options: {
18+
outputAssetBase: 'assets',
19+
}
20+
}
21+
}]
22+
}
23+
};

0 commit comments

Comments
 (0)