Ok, found an answer on this but there's a ton of other related things I found in the process that could probably help others.
First, now I understand what I wanted to do is install the current package as a local dependency. That can be done in the package.json
using the following syntax found in this answer.
{
"name": "@place/fn",
"dependencies": {
"@place/fn": "file:./"
}
}
Now, I can run npm i
to install that change and code the following test file:
import mainThing, { anotherThing } from '@place/fn';
When running the test file, the import will act as if it was installed into another package; better mimicking the intended use.
Another thing I discovered is that you can alias packages installed from npm using the syntax found in this answer.
"dependencies": {
"case-1.5.3": "npm:case@^1.5.3",
"kool": "npm:case@^1.6.1"
}
Which then allows you to do the following:
let Case = require('case-1.5.3');
let Kool = require('kool');
And finally, another thing I found is that Node@13 allows for a new key on the package.json
which maps directories found in this answer. There are other packages (like module-alias
) that do something similar with the big difference being the installed solutions (ie: module-alias
) only work from within the package you are working with. It seems like the new exports
key on package.json
will do the mapping for use in other packages.
// ./node_modules/es-module-package/package.json
{
"name": "es-module-package",
"exports": {
"./my/": "./src/js/lib/my/"
}
}
import thing from 'es-module-package/my/thing.js';
// Loads ./node_modules/es-module-package/src/js/lib/my/thing.js
Ultimately the purpose of all of this was to test that the style of syntaxes I provide outside the package could be tested from within the package instead of installing into another package and testing there. Now I can check that a common lodash import syntax works for my package.
import get from 'lodash/get'
(I wish I knew what the terminology was for requiring a clean, perhaps aliased, path of a package instead of destructuring the main export.)
import mainThing, { anotherThing } from '@place/fn';
where@place/fn
is the package itself that I am building. I'm already aware of your exampleimport Project from "../";
– Goosander