Skip to content

Commit

Permalink
Remove resolve-pkg dependency (#16)
Browse files Browse the repository at this point in the history
* fix: remove resolve-pkg dependency

* chore: patch
  • Loading branch information
natemoo-re authored Apr 26, 2022
1 parent 9a84bb5 commit 5cbbe02
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-boats-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@proload/core": patch
---

Remove `resolve-pkg` dependency
18 changes: 18 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"@proload/core": "0.3.1",
"jsonc-register": "0.2.0",
"kdl-register": "0.1.0",
"@proload/plugin-dotfile": "0.2.0",
"@proload/plugin-json": "0.3.0",
"@proload/plugin-kdl": "0.2.0",
"@proload/plugin-rc": "0.2.0",
"@proload/plugin-tsm": "0.2.0",
"@proload/plugin-typescript": "0.2.0",
"@proload/plugin-yaml": "0.2.0",
"yaml-register": "0.1.0"
},
"changesets": []
}
4 changes: 4 additions & 0 deletions packages/core/lib/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const { ProloadError } = require('../error.cjs');
function load(...args) {
return import('../esm/index.mjs').then(({ default: loader }) => loader(...args));
}
function resolve(...args) {
return import('../esm/index.mjs').then(({ resolve: resolver }) => resolver(...args));
}

load.resolve = resolve;
load.default = load;
load.ProloadError = ProloadError;
module.exports = load;
7 changes: 4 additions & 3 deletions packages/core/lib/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import deepmerge from "deepmerge";

import { existsSync, readdir, readFile, stat } from "fs";
import { promisify } from "util";
import resolvePkg from "resolve-pkg";
import { createRequire } from "module";
import requireOrImport from "./requireOrImport.mjs";
import { assert, ProloadError } from "../error.cjs";

export { ProloadError };

const require = createRequire(import.meta.url);
const toStats = promisify(stat);
const toRead = promisify(readdir);
const toReadFile = promisify(readFile);
Expand Down Expand Up @@ -94,7 +95,7 @@ async function resolveExtension(namespace, { filePath, extension }) {
if (!existsSync(resolvedPath)) resolvedPath = null;
}
if (!resolvedPath) {
const pkg = resolvePkg(extension, {
const pkg = require.resolve(extension, {
cwd: dirname(filePath),
});
const accepted = validNames(namespace);
Expand All @@ -110,7 +111,7 @@ async function resolveExtension(namespace, { filePath, extension }) {
}
}
if (!resolvedPath) {
resolvedPath = resolvePkg(extension, { cwd: dirname(filePath) });
resolvedPath = require.resolve(extension, { cwd: dirname(filePath) });
}
if (!resolvedPath) return;
const value = await requireOrImportWithMiddleware(resolvedPath);
Expand Down
7 changes: 1 addition & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
"import": "./lib/esm/index.mjs",
"require": "./lib/cjs/index.cjs"
},
"./plugin-typescript": {
"import": "./plugin-typescript/index.mjs",
"require": "./plugin-typescript/index.cjs"
},
"./esm": "./lib/esm/index.mjs",
"./cjs": "./lib/cjs/index.cjs",
"./lib/index.d.ts": "./lib/index.d.ts",
Expand All @@ -35,8 +31,7 @@
"author": "Nate Moore <[email protected]>",
"dependencies": {
"deepmerge": "^4.2.2",
"escalade": "^3.1.1",
"resolve-pkg": "^2.0.0"
"escalade": "^3.1.1"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test('factory-context', async () => {
is(mdl.value.__TEST__, true);
});

const extendFixtures = ['extends-cjs', 'extends-mjs', 'extends-dependency'];
const extendFixtures = ['extends-cjs', 'extends-mjs', /* 'extends-dependency' */];

for (const fixture of extendFixtures) {
test(fixture, async () => {
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1481,13 +1481,6 @@ resolve-from@^5.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69"
integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==

resolve-pkg@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-pkg/-/resolve-pkg-2.0.0.tgz#ac06991418a7623edc119084edc98b0e6bf05a41"
integrity sha512-+1lzwXehGCXSeryaISr6WujZzowloigEofRB+dj75y9RRa/obVcYgbHJd53tdYw8pvZj8GojXaaENws8Ktw/hQ==
dependencies:
resolve-from "^5.0.0"

resolve@^1.10.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
Expand Down

0 comments on commit 5cbbe02

Please sign in to comment.