I have a project structure like this:
__tests__
example
src
.bablerc
.eslintignore
.eslintrd
.gitignore
package.json
package-lock.json
README.md
and package.json parameters like:
{
"name": "",
"version": "0.0.1",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "jest"
},
"files": [
"src/"
],
"repository": {
"type": "git",
"url": "url"
},
"jest": {
},
"devDependencies": {
},
"peerDependencies": {
}
}
When I npm install this modules I only get src folder with an empty index.js file. The goal was to only have the user install all of the src folder and not the example part since that is an example app. I thought that "files": ["src/"], would solve this. However it's not doing what I would expect. I don't see anything that is in the src folder. It's empty!
npm docs say:
The optional files field is an array of file patterns that describes
the entries to be included when your package is installed as a
dependency. File patterns follow a similar syntax to .gitignore, but
reversed: including a file, directory, or glob pattern (*, **/, and
such) will make it so that file is included in the tarball when it’s
packed. Omitting the field will make it default to [""], which means
it will include all file
How do I allow the user to install all of the src folder and ignore the example folder?
I'm on npm 5.6.0 and node v9.11.2
Almost there! Files entry behave like in a line a .gitignore. That works:
"files": ["src"]
For testing purposes, you can run npm pack --dry-run to check in the pack reports what files would be included when running npm install on the package you're developing.
Related
I have an NPM package that I am creating in Typescript which just contains my type interfaces.
I currently have a folder structure like this:
project
│ index.ts
│
└───types
│ restaurant.ts
│ menus.ts
and package.json that points to the index file:
{
"name": "my-package",
"version": "1.0.0",
"description": "Shared type definitions",
"type": "module",
"main": "./index.ts",
"source": "./index.ts",
"scripts": {
"tsc": "tsc --noEmit"
},
"license": "ISC",
"devDependencies": {
"typescript": "^4.8.4"
}
}
I can link this with another package in "project A" and all works well.
But as soon as I move my index.ts and type files into a directory called src, the link no longer works
Cannot find module 'my-package' or its corresponding type declarations.
I have tried removing the symlink / reinstalling the linked package as well as updating my package.json file of my shared package to "main": "./src/index.ts", but to no avail
How am I supposed to create an NPM package which points to my src or even a dist file?
What you are looking for is a monorepo project.
Take a look at turborepo, which does exactly what you want.
You can also try lerna, but I personally prefer the other one.
I'm starting a CDK lambda project which gets the source code like this:
code: lambda.Code.fromAsset("resources"),
handler: "synthetic_test.main",
There's a single javascript file synthetic_test.js in that folder.
This seems to work but I can't figure out how to make it so that I could do:
const axios = require("axios");
in that file.
For some reason it seems to be able to import:
const AWS = require("aws-sdk");
but nothing else.
I did yarn add axios which added it to the package.json of my CDK project. But that does not really seem to help the lambda a lot.
The AWS Lambda runtime environment includes native language libraries and the relevant language-specific AWS SDK.
It does not contain arbitrary third-party packages. You need to either package those dependencies with your code or create a Lambda Layer that includes the dependencies and configure your Lambda function to use the Lambda Layer.
To package CDK app dependencies, see #aws-cdk/aws-lambda-nodejs and here.
I went with packaging dependencies with my code
My cdk went to
// 👇 define PUT account function
const putAccountLambda = new lambda.Function(this, "put-account-lambda", {
runtime: lambda.Runtime.NODEJS_14_X,
handler: "main.handler",
code: lambda.Code.fromAsset(path.join(__dirname, "/../src/put-account/dist")),
environment: {
REGION,
ADMINS_TABLE,
ADMINS_TABLE_PARTITION_KEY,
HASH_ALG,
}
})
With dist being the folder with a packed main.js file. And this file has a handler entrypoint. I had to update the package.json of these lambdas with packed dependencies.
{
"name": "put-account",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode=production --env env=prod",
"build:dev": "webpack --mode=development --env env=dev"
},
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^5.66.0",
"webpack-cli": "^4.9.1",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"aws-sdk": "^2.1058.0",
"crypto": "^1.0.1",
"uuid": "^8.3.2"
}
}
And I updated the package.json of my cdk project to these scripts.
"build": "tsc && npm run build:webpack",
"build:webpack": "for file in ./src/*; do (cd $file && npm i && npm run build) & done",
"build:beta": "tsc && npm run build:webpack:beta",
"build:webpack:beta": "for file in ./src/*; do (cd $file && npm i && npm run build:dev) & done",
Notice that my file structure is as follows:
./
bin
lib
src
package.json
With src holding the source code for my project's lambdas.
I am not sure if you are familiar with webpack, but I have divided my webpack configuration in common, dev, prod.
A dev webpack configuration is specially useful for debugging because otherwise you lose line numbers among other useful information when something goes wrong on runtime.
When getting started with nuxt 3, it creates TypeScript project by default.
Is there a way to move to JavaScript?
I have tried:
Rename nuxt.config.ts to nuxt.config.js
delete tsconfig.json
add jsconfig.json
Contents of nuxt.config.js
export default {
};
contents of package.json
{
"private": true,
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"nuxt3": "latest"
}
}
Still the .nuxt folder creates TypeScript files
No, unfortunately in the current nuxt3 version (3.0.0-27268729.5b8e10f), there is no configuration to disable the output of those type declaration files.
While the generated .d.ts file are intended to help TypeScript developers, Nuxt does not require app source to be written in TypeScript. The .d.ts files should have no impact on your JavaScript development other than the slight delay in generating those files.
When I try to publish a module in npm repository it is not taking lib folder. I added it in package.json file as below but it is not taking that lib folder. Lib folder contains files that are used by module.
{
"name": "sample",
"version": "1.0.0",
"description": "",
"main": "sample.js",
"directories":{
"lib": "/lib"
}
}
remove the / from lib, so your package.json becomes
{
"name": "sample",
"version": "1.0.0",
"description": "",
"main": "sample.js",
"directories":{
"lib": "lib"
}
}
Add the files to package.json
{
"files": [ "lib" ]
}
For files or directories ensure the path or paths are specified as expected. Rather than /lib you probably want ./lib. Verify the files and folders you want to publish are not being ignored by a .npmignore or .gitignore dotfile in the lib directory of your project. Also, if there's a separate package.json file in lib you'll wan to check that too.
For more information see:
https://docs.npmjs.com/files/package.json#files
https://docs.npmjs.com/files/package.json#directories
I need to manage CryptoJS with Bower. This project is hosted on code.google.com. Can be downloaded as zip file or through the SVN.
Can Bower download an uncompress the zip file or download all components from the SVN and put them in the crypto folder?
.bowerrc file, defining the download folder:
{
"directory": "app/vendor"
}
I've tried this component.json file (fails, downloads the page itself):
{
"name": "Backbone Client",
"version": "1.0.0",
"dependencies": {
"crypto": "http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/"
}
}
Another try (hmac.js overriders core.js and it's saved as index.js):
{
"name": "Backbone Client",
"version": "1.0.0",
"dependencies": {
"crypto":
"http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core.js",
"crypto":
"http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/hmac.js"
}
}
Found the way reading Bower official page:
As you can see, packages can be installed by name, Git endpoint,
GitHub shorthand, URL or local path. If you install from a URL that
points to a zip or tar file, bower will automatically extract its
contents.
component.json:
{
"name": "Backbone Client",
"version": "1.0.0",
"dependencies": {
"crypto-js": "http://crypto-js.googlecode.com/files/CryptoJS%20v3.1.2.zip"
}
}