In this project the README.md displays the logo/pnglogo.png logo at the top of the README.md file.
We'd like the same logo to display on NPM. So we copy it into the dist/fs-validator directory where the publish files are located. This is the npm script (From package.json):
"p": "cp README.md ./projects/fs-validator/ && npm run bp && npm run b && cp -r logo ./dist/fs-validator/ && cd dist/fs-validator/ && npm publish",
If I understand correctly, this should publish the logo directory along with the other files. However the logo is not showing up at the top of the README.md within NPM. How can I fix that?
I moved the logo to the root of the repository and changed the README.md to include it like this:
![Validator](pnglogo.png)
As that works for publishing with this repository:
https://github.com/fireflysemantics/slice
However I'm still not getting any success.
Figured it out. The package.json that I was publishing did not have the Github repository fields included.
{
"name": "#fireflysemantics/validator",
"version": "0.0.9",
"peerDependencies": {
"#fireflysemantics/is": "*",
"#fireflysemantics/validatorts": "*"
},
"dependencies": {
"tslib": "^2.2.0"
}
}
Apparently these are needed in order for NPM to know where the image is located.
I changed package.json to incoulde the repository data so that it now looks like this:
{
"name": "#fireflysemantics/validator",
"version": "0.0.11",
"license": "MIT",
"bugs": {
"url": "https://github.com/fireflysemantics/validator/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fireflysemantics/validator.git"
},
"keywords": [
"Validation",
"Javascript",
"Typescript",
"Angular Package Format"
],
"peerDependencies": {
"#fireflysemantics/is": "*",
"#fireflysemantics/validatorts": "*"
},
"dependencies": {
"tslib": "^2.2.0"
}
}
And now the logo shows up.
Related
My goals is to create a CLI script to install globally (npm i -g #born05/cli).
My package.json:
{
"name": "#born05/cli",
"version": "1.0.7",
"description": "The Born05 handy-dandy development Command Line Interface",
"main": "lib/cli.js",
"author": {
"name": "Niels Wijers",
"email": ""
},
"bin": {
"born05": "lib/cli.js"
},
"engines": {
"node": ">=12.0.0"
},
"license": "ISC",
"publishConfig": {
"#born05:registry": "https://gitlab.born05.com/api/v4/projects/147/packages/npm/"
},
"bundleDependencies": false,
"deprecated": false,
"dependencies": {
"findit": "^2.0.0",
"inquirer": "^7.3.3",
"js-yaml": "^4.0.0",
"tar": "^6.1.0"
}
}
The script is created and tested locally and it works, even after npm link the script is working when typing born05 in my terminal. But after publishing and installing it globally it fails to link the cli.js to the bin dir but the package is installed successfully.
My .gitlab-ci.yml
stages:
- publish
publish:
stage: publish
image: node:15.0-slim
before_script:
- npm install
- |
{
echo "#born05:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
} | tee --append .npmrc
script:
- npm publish
My .npmrc
#born05:registry = "https://gitlab.born05.com/api/v4/packages/npm/"
//gitlab.born05.com/api/v4/packages/npm/:_authToken = (protected)
I hope anyone can help me.
I experienced the same issue, and my solution was to export the parameter manually:
- npm install
- |
{
echo "#born05:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
} | tee --append .npmrc
- export NPM_CONFIG_REGISTRY=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/
There is a similar post here:
My custom NPM Package is not found,
but that did not resolve my issue.
Could not find a declaration file for module '#dc_microurb/common'.
'/Users//Projects/ticketing/auth/node_modules/#dc_microurb/common/build/index.js'
implicitly has an 'any' type. Try npm install #types/dc_microurb__common if it exists or add a new declaration
(.d.ts) file containing `declare module '#dc_microurb/common';
There is no #types/dc_microurb__common and I am unclear as to why it is suggesting to create a new .d.ts file, when that happens automatically during the build process.
This is the package.json file inside my published package:
{
"name": "#dc_microurb/common",
"version": "1.0.5",
"description": "",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"./build/**/*"
],
"scripts": {
"clean": "del ./build",
"build": "npm run clean && tsc",
"pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"del-cli": "^3.0.1",
"typescript": "^4.0.5"
},
"dependencies": {
"#types/cookie-session": "^2.0.41",
"#types/express": "^4.17.9",
"#types/jsonwebtoken": "^8.5.0",
"cookie-session": "^1.4.0",
"express": "^4.17.1",
"express-validator": "^6.6.1",
"jsonwebtoken": "^8.5.1"
}
}
Anybody with experience in publishing packages on npm where TypeScript is involved? I am unclear as to why this package is not being found by my auth service when it is successfully installed inside that service.
Did I mess up in the way I am exporting inside my common/src/index.ts file?
export * from './errors/bad-request-error';
export * from './errors/custom-errors';
export * from './errors/database-connection-error';
export * from './errors/not-authorized-error';
export * from './errors/not-found-error';
export * from './errors/request-validation-error';
export * from './middlewares/current-user';
export * from './middlewares/error-handler';
export * from './middlewares/require-auth';
export * from './middlewares/validate-request';
Does it all have to be inside a module.exports instead?
So after reviewing a few blogs on Medium on how this is done, I noticed a couple of things.
Inside my tsconfig.js, this was missing:
/* Advanced Options /
"forceConsistentCasingInFileNames": true / Disallow inconsistencies */
So I manually added it in, secondly, I noticed something I meant to remove earlier but forgot. So instead of this:
{
"name": "#dc_microurb/common",
"version": "1.0.5",
"description": "",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"./build/**/*"
],
I needed to have it like this:
{
"name": "#dc_microurb/common",
"version": "1.0.6",
"description": "",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"build/**/*"
],
After making those couple of corrections, now my package is available to my auth service.
I have a css build task that merges resources from bower dependencies and my own css.
The build task is part of project that uses git source control. The project has been running correctly for well over a year.
Up until yesterday, everything was working correctly on my windows laptop, when I reinstalled my npm dependencies that run the build task.
Below is a simplified example
gulpfile.js
var gulp = require('gulp'),
$ = require('gulp-load-plugins')();
gulp.task('default', function () {
return $.merge (
gulp.src('./bower.json')
.pipe($.mainBowerFiles('**/*.css', {
includeDev: 'exclusive',
group: 'css'
})
),
gulp.src(['./source/css/styles.css'])
)
.pipe($.plumber())
.pipe($.concat('stylesheet.css'))
.pipe(gulp.dest('./build/css'))
});
package.json
{
"name": "merge",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-load-plugins": "^1.5.0",
"gulp-main-bower-files": "^1.6.2",
"gulp-merge": "^0.1.1",
"gulp-plumber": "^1.1.0",
}
}
And bower.json
{
"name": "merge",
"description": "",
"main": "gulpfile.js",
"authors": [
""
],
"license": "ISC",
"homepage": "",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"devDependencies": {
"normalize-css": "^7.0.0",
"reset-css": "^2.2.1"
},
"group": {
"css": [
"reset-css",
"normalize-css"
]
}
}
Prior to yesterday the task would merge both sources declared in $.merge(...). Since yesterdays' npm install I am finding that the merge will only output the result for the first declared source.
After some testing I have found that if I reverse the order of the merge sources than both sources are merged to the set output destination.
var gulp = require('gulp'),
$ = require('gulp-load-plugins')();
// the order of the sources has been reversed
gulp.task('default', function () {
return $.merge (
gulp.src(['./source/css/styles.css']),
gulp.src('./bower.json')
.pipe($.mainBowerFiles('**/*.css', {
includeDev: 'exclusive',
group: 'css'
})
)
)
.pipe($.plumber())
.pipe($.concat('stylesheet.css'))
.pipe(gulp.dest('./build/css'))
});
The problem with this solution is that that output content reversed, which may cause issues with style inheritance etc. This change to a successful output makes me think there may be an issue with how and where .pipe($.mainBowerFiles(...) is declared.
I've also tried replacing installed modules for gulp-merge and gulp-main-bower-files respectively with merge2 and main-bower-files.
Using either one or both solved the problem, however this isn't an ideal workaround as it means an update to the gulp task and installed modules.
This sudden failure to output tasks merge css ( or js ) in my project has real issues for any historic commit or branch in the project.
Is there away I can diagnose the failure of the original $.merge(...), or a way that I can retroactively replace gulp-merge with merge2 across all commits my git project and any branches?
This is my first time using a private repo as a dependency in another project. I think I am doing it right, but the dependency is not available in the new project after install and is not in node_modules.
Following this post I can see that I am including it in the package.json correctly like:
"myPackage": "git+https://github.com/myusername/mygitrepository.git"
When I run npm install on this package, I see this that it does not have an error, but after this dependency in the list, it is shown with extraneous(git+https://github.com/myusername/mygitrepository.git).
Even though there is the extraneous issue, there is no error, and the dependency is not available or listed in node_modules.
Update: repo_A package.json
{
"name": "project-name",
"version": "1.0.0",
"description": "Backend utility functions",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/user/repo.git"
},
"author": "me",
"license": "ISC",
"bugs": {
"url": "https://github.com/user/repo/issues"
},
"homepage": "https://github.com/user/repo#readme",
"dependencies": {
"lodash": "^4.17.4",
"mongodb": "^2.2.25",
"redis": "^2.7.1",
"winston": "^2.3.1"
}
}
Update: repo_B package.json
{
"name": "main-project-name",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/user/repo.git"
},
"author": "someone else",
"homepage": "https://github.com/user/repo.git",
"dependencies": {
"async": "2.1.4",
"chai": "^3.5.0",
"langs": "1.1.0",
"lodash": "4.13.1",
"node-stopwatch": "0.0.1",
"request": "2.74.0",
"winston-loggly": "^1.3.1",
"utils": "user/repo_A.git#master"
},
"scripts": {
"test": "mocha"
}
}
Update for latest steps
Here are the steps I am following now to test each possible solution, followed by the output:
rm -rf node_modules
npm cache clean
npm install
Output
├─┬ async#2.1.4
│ └── lodash#4.17.4
├─┬ chai#3.5.0
│ ├── assertion-error#1.0.2
│ ├─┬ deep-eql#0.1.3
│ │ └── type-detect#0.1.1
│ └── type-detect#1.0.0
├── util#1.0.0 extraneous (git+ssh://git#github.com/user/repo_A.git#commit-ish)
.......
If you specify https then that will be looking for a login user and password I believe, which I don't think it can load automatically. I would list it simply as "user/repo" and make sure that machine has an ssh key on it that is in github like the setup described in help such as https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux and that things are setup so that pulling down that repo does not require user interaction.
EDIT: After testing, I think the issue is that your name in the package.json does not match how you have listed it in your main project's dependencies. In my test, this resulted in the modules being installed but I got the extraneous message.
I just created a node_module with a dependency with 'validator'.
But when I install it from npm, it doesn't install the 'validator' module in its own node_module directory. I don't understand why, but it's the first time I create my own node module.
package.json:
{
"name": "validator-extended",
"description": "String validation and sanitization based on validator.js",
"version": "1.1.0",
"homepage": "https://github.com/Ayolan/validator-extended",
"keywords": [
"validator",
"validation",
"validate",
"sanitization",
"sanitize",
"sanitisation",
"sanitise",
"assert",
"extend",
"extended"
],
"author": "Vadorequest <https://github.com/Vadorequest>",
"main": "app.js",
"bugs": {
"url": "https://github.com/Ayolan/validator-extended/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Ayolan/validator-extended.git"
},
"engines": {
"node": ">= 0.8"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/Ayolan/validator-extended/raw/master/LICENSE"
}
],
"dependencies": {
"validator": "~3.1"
}
}
I also have a .npmignore file with this:
########################
# node.js / npm
########################
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
########################
# misc / editors
########################
*~
*#
.DS_STORE
.netbeans
nbproject
.idea
Should I push the node_modules/ directory into my git repository?
You should remove your existing package.json and run
npm init
to properly initialise your project. Once that's done, add validator to the dependencies. This should allow npm install to work properly and install your dependencies. Don't commit your node_modules folder.