yortus / require-self Goto Github PK
View Code? Open in Web Editor NEWLets you require('foobar') from within foobar itself
License: MIT License
Lets you require('foobar') from within foobar itself
License: MIT License
Very useful module. But I cannot make it working with Visual Studio Code Intellisense.
Help appreciated.
Hi,
I've been using require-self for a few years, but still found it a hack, that should be solved directly in npm.
Happy to say I think I've found a way to replace this:
for a module called myModule simply put "myModule": "file:.",
in your dev dependencies.
This creates a symlink to the parent folder, the same as what require self is doing.
I think that's a good solution for the problem require-self is solving.
I'm wondering if it would make sense for require-self to generate a relative path to the module rather than absolute? That way, the user can move their repo around on disk without having to re-run require-self
.
I feel the feature of this module is something that is missing from node.js itself.
Do you have any idea if there is any open issue to solve that situation directly in node so this module is not needed ?
Using require-self
with 0.2.2
does not work with an error.
The actual error log is as follows:
/home/travis/build/kenchan0130/babel-preset-google-apps-script/node_modules/require-self/bin/require-self:23
throw e;
^
ReferenceError: tsDeclPath is not defined
at Object.<anonymous> (/home/travis/build/kenchan0130/babel-preset-google-apps-script/node_modules/require-self/bin/require-self:20:29)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
You can also see it at https://travis-ci.org/github/kenchan0130/babel-preset-google-apps-script/builds/657483044.
Node.js: v8, v10, v12
require-self: 0.2.2
This package solves the problem for when the main file is accessed. Frequently though, other files are accessed, like require('lodash/reduce')
. Would you accept a PR that would link the package to node_modules
? I'd use this package of mine for symlinking - symlink-dir. It works well cross-platform and is used at pnpm as well.
P.S. some packages already use this approach, like webpack https://github.com/webpack/webpack/blob/master/ci/travis-install.sh
My module has a name like this: "name":"@myCompany/my-module"
in this case require-self should be exporting ../../ instead of just ..
Hi,
As explained in NPM doc, prepublish script will soon change a little.
Having this in mind, I wonder if you should change the readme file to add require-self to postInstall or prepare hook instead of prepublish ?
I think the most common use would be postInstall, what do you feel about that ?
If I try to use require-self
with Babel or mocha
, while having "main"
point to "lib/index.js"
and using Babel to transpile ./src
to ./lib
, my requires load from ./lib
whereas the source of my tests still sits in ./src
. And this is not what I intend...
I've applied Artem Govorov's suggestion to patch require()
in order to get my tests running.
Do you see an other way to get mocha
work with my setup?
Thanks for this package! It serves a useful niche purpose.
I just wanted to discuss the proper usage. I'm rather new to the JavaScript/Node.js world, so I welcome any constructive feedback.
The README.md
says to use require-self
in the prepare
script in the package.json
:
"devDependencies": {
"require-self": "^0.2.3"
},
"scripts": {
"prepare": "require-self"
}
After that, I used the setup-node
GitHub Action to publish my package to the npmjs registry. When I did, I ran into this problem:
npm publish
shell: /bin/bash -e {0}
env:
NPM_CONFIG_USERCONFIG: /home/runner/work/_temp/.npmrc
NODE_AUTH_TOKEN: ***
> [email protected] prepare .
> require-self
sh: 1: require-self: not found
On reflection, I guess this error makes sense. But then it seems like using require-self
in the prepare
script would require running npm install
before npm publish
to make sure require-self
is found. It doesn't seem like npm install
should be necessary at that point.
Is my understanding correct? Is it typical to run npm install
just before npm publish
, or is that a situation created by the thing that require-self
does?
As an aside, my current solution is to not have require-self
in the prepare
script but to run it directly after npm install
and before npm test
in CI (stoicism-compendium/retext-spell-file#20).
First off, thanks for this project, it saved me tons of manual steps. This isn't really an issue, but might be worth adding to the README. I just wanted to post this incase anyone else uses this repo within a typescript project.
In order for the import to provide the proper declarations you need to add a declaration to your project typings:
<root>/typings/index.d.ts
declare module 'foobar';
where foobar is the name from your package.json
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.