Skip to content

Commit

Permalink
Fix ERR_PACKAGE_PATH_NOT_EXPORTED error on loading option-t.
Browse files Browse the repository at this point in the history
This error happens by this change in [Node,js v13.10](nodejs/node#31625) and I think we can regard this problem as the regression of this library.

For the future, we should wait nodejs/node#32107 but it is still in progress.
This patch will try to workaround for it.

* nodejs/node#31625
* nodejs/node#32107
* babel/babel#11216
  • Loading branch information
tetsuharuohzeki committed Mar 26, 2020
1 parent d824a11 commit 7c27e17
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "22.2.2",
"description": "Option type implementation whose APIs are inspired by Rust's `Option<T>`.",
"type": "commonjs",
"main": "cjs/index.js",
"main": "./cjs/index.js",
"files": [
"CHANGELOG.md",
"cjs/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
'use strict';

const { loadHistoricalPathInfo, addHistoricalPathToExportsFields } = require('./compatibility');
const assert = require('assert');

const {
loadHistoricalPathInfo,
addHistoricalPathToExportsFields,
} = require('./compatibility');

const BASE_DIR = __dirname;

function addMainFieldFromPackageJSON(targetObject, manifestInfo) {
const mainPath = manifestInfo.main;
assert.strictEqual(typeof mainPath, 'string', `package.json's 'main' field is not string`);
assert.ok(mainPath.startsWith('./'), `package.json's 'main' field should start with ./`);

// eslint-disable-next-line no-param-reassign
targetObject['.'] = mainPath;
}

async function addExportsFields(json) {
const o = Object.create(null);

const histricalJSPathList = await loadHistoricalPathInfo(BASE_DIR, '../../../pkg_files.json');
addHistoricalPathToExportsFields(o, histricalJSPathList);

// For the future, we may have a chance to remove this
// when https://github.com/nodejs/node/issues/32107/ has been fixed.
addMainFieldFromPackageJSON(o, json);

// eslint-disable-next-line no-param-reassign
json.exports = o;
}
Expand Down

0 comments on commit 7c27e17

Please sign in to comment.