Skip to content

Commit

Permalink
fix: make "resolve" external, fixes pnp (#165)
Browse files Browse the repository at this point in the history
* fixes #163
  • Loading branch information
goloveychuk authored Jul 13, 2022
1 parent 7c13ff4 commit d22269d
Show file tree
Hide file tree
Showing 10 changed files with 856 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
run: yarn install
- name: Run Tests
run: yarn test
- name: Run yarn pnp tests
if: matrix.os == 'ubuntu-latest'
run: yarn test-pnp
- name: Coverage
if: matrix.os == 'ubuntu-latest'
run: yarn test-coverage
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
"license": "MIT",
"main": "./dist/index.js",
"scripts": {
"build": "ncc build src/asset-relocator.js",
"build": "ncc build src/asset-relocator.js -e resolve",
"codecov": "codecov",
"test": "npm run build && jest",
"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",
"test-coverage": "jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov"
},
"files": [
"dist/*"
],
"dependencies": {
"resolve": "^1.10.0"
},
"devDependencies": {
"@vercel/ncc": "^0.25.1",
"acorn": "^8.3.0",
Expand All @@ -31,7 +35,6 @@
"memory-fs": "^0.4.1",
"node-gyp-build": "^4.2.1",
"node-pre-gyp": "^0.12.0",
"resolve": "^1.10.0",
"resolve-from": "3.0.0",
"rollup-pluginutils": "^2.8.2",
"semantic-release": "^17.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/asset-relocator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getPackageScope = require('./utils/get-package-scope');
const { pregyp, nbind } = require('./utils/binary-locators');
const handleSpecialCases = require('./utils/special-cases');
const { getOptions } = require("loader-utils");
const resolve = require('resolve');
const resolve = require('resolve'); //resolve should be external to be patched by yarn
const mergeSourceMaps = require('./utils/merge-source-maps');
const os = require('os');
const nodeGypBuild = require('node-gyp-build');
Expand Down
6 changes: 6 additions & 0 deletions test/yarn-pnp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.yarn/cache
/.yarn/install-state.gz
/.yarn/unplugged
/yarn.lock
/.pnp.*
/assets-plugin-tarball.tgz
786 changes: 786 additions & 0 deletions test/yarn-pnp/.yarn/releases/yarn-3.2.1.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/yarn-pnp/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-3.2.1.cjs
3 changes: 3 additions & 0 deletions test/yarn-pnp/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
sumPath: require.resolve('lodash/sum')
}
16 changes: 16 additions & 0 deletions test/yarn-pnp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"private": true,
"scripts": {
"build": "rm -rf dist && webpack",
"test": "node test.js"
},
"dependencies": {
"lodash": "^4.0.0"
},
"devDependencies": {
"@vercel/webpack-asset-relocator-loader": "file:./assets-plugin-tarball.tgz",
"webpack": "^5",
"webpack-cli": "^4"
},
"packageManager": "yarn@3.2.1"
}
12 changes: 12 additions & 0 deletions test/yarn-pnp/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

const assert = require('assert');
const fs = require('fs');
const path = require('path');

const sumFilePath = path.resolve(__dirname, './dist/assets/sum.js');


assert.equal(fs.existsSync(sumFilePath), true)
assert.equal(require('./dist/main').sumPath, sumFilePath)

console.log('pnp test succeed!')
23 changes: 23 additions & 0 deletions test/yarn-pnp/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
target: 'node',
mode: 'production',
entry: {
main: './main.js'
},
output: {
path: __dirname + '/dist',
libraryTarget: 'commonjs'
},
module: {
rules: [{
test: /\.m?js$/,
parser: { amd: false },
use: {
loader: require.resolve('@vercel/webpack-asset-relocator-loader'),
options: {
outputAssetBase: 'assets',
}
}
}]
}
};

0 comments on commit d22269d

Please sign in to comment.