JSPM not creating js file in root directory - jspm

Overview
I'm trying to install the bootstrap-wysiwyg package in my ES6 project using JSPM.
Usually you can just install a package using the command
jspm install npm:bootstrap-wysiwyg
And JSPM will take care of the config.js file and create the entry JS file in the jspm_packages folder.
My problem
For this particular package, it does create the config.js entry to the bootstrap-wysiwyg JS file in the root directory, but it does not create that JS file itself.
Files
Config.js
"bootstrap-wysiwyg": "npm:bootstrap-wysiwyg#1.0.4",
Import
import stuff from 'bootstrap-wysiwyg';
Error message
GET http://localhost:9000/jspm_packages/npm/bootstrap-wysiwyg#1.0.4.js 404 (Not Found)
Question
How can I make sure JSPM creates that file? I could make one myself, but then version control is obviously broken.

The module your are trying to import is missing "main" entry in its package.json: https://github.com/steveathon/bootstrap-wysiwyg/blob/master/package.json Therefore, JSPM cannot create the main import. You have to either import files directly from the module (i.e. import stuff from 'bootstrap-wysiwyg/js/smth') or create an override for this package which will define "main" for the package (https://github.com/jspm/registry/wiki/Configuring-Packages-for-jspm#testing-configuration).

Related

node or npm: How to see the source code of a package installed

Like in python i install a package using
pip install django
inside a virtualenv,
Then it puts all the files in site-packages folder. and then i can import the package using
from django.core import mail
But i can easily browse the code of django/core in site-packages
Similarly if I install a package using npm can i see the source of that
Eg:
import React, { useEffect } from "react";
Now i want to see the react file and go through the React and useEffect
Is it possible
I do not have background in Python. So, can't explain or compare in Python way. But, yes! You can read or go through the source code in most of the cases.
Now, talking about the specific example you mentioned in question - React. Things are little complicated as we're talking about one of the popular library. You may wouldn't find React.js or react.js file directly. But, that doesn't mean you can read the source code. Let's do it.
Create an application that has react as dependency (You can create an application using create-react-app).
In this application, you'll have node_modules folder. Within this node_modules, you'll have folder after the name of dependency e.g. react. Go inside this folder.
You'll find the package.json file. Open it and look for main. The main is an entry point of the program/package. It mentioned index.js. So, let's open the index.js file.
If you open the index.js, you'll see that based on environment, they're requiring the react.production.min.js or react.development.js file. Open this react.development.js file from cjs folder.
In this file, do a search for useEffect. You will find a function with the same name.
But, I wouldn't recommended you to read the code in this way, if you're planning for React. You may try this solution. Also, if you're planning to read the source code as starting point, why not start with simple and easy to read packages? And don't forget that if not all then most of the packages are there on GitHub and on NPM website, you'll see the link for the Repository.

Is it possible to import a symlinked file and have the imported files imports resolve from the symlinked location and not the original one

eg:
A project directory looks like.
main.js
node_modules/dependency.js
linkedFile.js <-- this is a symlink to /someotherplace/linkedFile.js
package.json
main.js contains import foo from 'linkedFile';
linkedFile.js contains:
import dep from 'dependency';
However this throws an error because node looks for node_modules/dependency.js in /someotherplace/ rather than in the project root.
The desired reason for this is so that some configuration files that are shared amongst many modules can be updated without having to put them in a module and having to run an update for each module before they are applied.
Is it possible to import the symlinked file in a way that causes the symlinked file imports to resolve from the symlink location. Or how could I resolve this problem in another way?
(Currently running node 8.15.0)

Importing a subfolder from a package

I'm trying to use gtfs-realtime-bindings' node module.
The published module on npm is outdated so I'm downloading directly from github. However, gtfs-realtime-bindings is a super repo has subfolders for a lot of different environments.
How can I specify a subfolder in my require?
After downloading and extracting the zip file, you can npm install the relative path to your dependencies by running it in the root of your project like this:
npm i ../gtfs-realtime-bindings/nodejs --save
This is assuming that you've extracted the git repository zip adjacent to the project root directory. In your code you can then require('gtfs-realtime-bindings') like you would any other dependency installed via npm.
Are you downloading the repo and inserted on your source code? You should be able to use import or require from anywhere, example.
code
__src
____index.js
__gtfs-realtime-bindings
____nodejs
____java
You should be able to get the nodejs files from the index.js using
import nodejs from "../gtfs-realtime-bindings/nodejs";
or
const nodejs = require("../gtfs-realtime-bindings/nodejs");
Obviously, this depends on what you are trying to get, I don't know that repo, but this should work

Node: Import Typescript library with npm/yarn

I have a Node-Typescript project. That project has a dependency on another Typescript project. The dependency points directly to my Bitbucket repository. When I run "yarn install" the whole repository is cloned into my node_modules. That's perfect. In the root directory of my library-project is a index.ts file which contains the line "export * from './source'" to make it all available. I import and use some classes from the library in my code.
When I compile the project I get the exception: "Cannot find module './source'.". Furthermore it is not possible to automatically import the classes in Intellij.
What am I doing wrong?
Note:
I know, that the "right" way for libraries would be to generate JS and typing files and put the compiled source in to a private NPM repository. Since I am the only one that uses that library, I would like to have a simpler approach and just import the uncompiled Typescript into my project.

Angular2 module as npm module

I have an Angular2 project. In it I have a DisplayModule which contains components/directives/pipes/services used to do display stuff.
What do I have to do to make this a npm module which I can them load in other projects.
So far I have:
Extracted the folder as in a separate git folder, which contains the display.module.ts file in which I import and export all the relevant things from within this folder.
Tried to find what to do with this folder so that I can import it. From my understanding the steps are as follows:
a) do something to compile it into js files
b) export those js files as a package
c) publish those js files as a private npm package
d) include this package with npm install in another project
As you have probably guessed I have no idea how to do all the points under 2.
Please help

Resources