I believe there are some non-standard package.json keys out in the wild (like unpkg or jsnext). I think there's even one for style.
Is there any pseudo standard out there that others are using to define the location in their packages where static assets (images, fonts, etc.) live?
Something like:
{
"name": "my-package",
"main": "dist/index.cjs.js",
"assets": "dist/static"
}
You can use the directories or files key for that.
"files": [
"./src/assets/"
],
"directories": {
"assets:": "./src/assets"
}
Related
I have a project that I've built with nx and I'm deploying it to Google App Engine.
It needs app.yaml in the same folder.
Is there a way to tell nx builder to copy that extra file to the build directory next to everything else?
I guess you figured it out by now, but if anyone is still looking for a solution;
In project.json you can specify assets for targets so if you need app.yaml you can do something like this:
...
"targets": {
"build": {
"executor": "#nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/example",
"main": "apps/example/src/index.ts",
"tsConfig": "apps/example/tsconfig.app.json",
"assets": [
"apps/example/*.md",
"apps/example/src/app.yaml" <-- specify your path here
]
}
}
...
I am developing fullstack NPM packages with multiple entrypoints (namely client, server and sometimes tests), using the exports property of package.json.
I also use a small hack to make TS work with exports until it's officially supported (see this Stack Overflow post, this hackish solution and this ticket).
The package.json ends up looking like this:
{
"name": "#vulcanjs/graphql",
"version": "0.4.7",
"main": "./dist/index.js",
"files": [
"dist/"
],
"exports": {
".": "./dist/index.js",
"./server": "./dist/server/index.js",
"./testing": "./dist/testing.js"
},
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"server": [
"./dist/server/index.d.ts"
],
"testing": [
"./dist/testing.d.ts"
]
}
},
"description": "Vulcan graphQL schema generator",
...
You can then import using either #vulcanjs/graphql for shared code, and #vulcanjs/graphql/server for Node.js-only code.
It works perfect in my Next.js app. However, it seems to break Jest moduleNameMapper.
First, I had this:
moduleNameMapper: {
"#vulcanjs/(.*)": [
"<rootDir>/node_modules/#vulcanjs/$1",
],
},
The error is:
Configuration error:
Could not locate module #vulcanjs/graphql/server mapped as:
[
"/code/vulcan-next/node_modules/#vulcanjs/graphql/server",
].
The problem is that it tries to find a package named #vulcanjs/graphql/server: yet "server" is not a different package, it's an entrypoint of #vulcanjs/graphql.
I've also tried this:
moduleNameMapper: {
"#vulcanjs/(.*)/(.*)": [
"<rootDir>/node_modules/#vulcanjs/$1",
],
},
With this config, #vulcanjs/graphql/server is mapped to #vulcanjs/graphql. The problem is that now, server code is not found. I've checked and the problem is that this solution totally removes the /server: so #vulcanjs/graphql/server points to the main entrypoints instead of the server entrypoint.
Finally I did try to remove the moduleNameMapper, but then #vulcanjs/graphql/server package is not found by Jest. Note that I need the mapper for a use case I did not demonstrate here, so getting rid of it is possible but not the best solution.
The bug can be reproduced by installing the framework: https://github.com/VulcanJS/vulcan-next. You can clone, yarn install, unskip the test in src/models/tests/sampleModel.server.test.ts and run yarn run test:unit sampleModel. It will show the error.
Any idea how I could fix this?
I used to develop web sites with C# or Javascript with Visual Studio and IIS.
I've decided to upgrade to newer tools and try to create a simple web site with VSCode, NodeJS and TypeScript that I'll deploy to Azure later but each time I try a new sample, I get lost as I have the feeling it doesn't do what I want.
I created a TSConfig.json file with this minimum, I understood it creates a "project" in TypeScript:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}
A simple main.ts file:
class Startup {
public static main(): number {
console.log('Hello World');
return 0;
}
}
Startup.main();
A simpliest index.html file that references the generated main.js file
I wanted to
- compile my web site using "$tsc-watch" to benefit from that automatic recompile
- launch the web site in NodeJS
- Open the web page in Chrome and being able to debug
But I am wondering, is it the right approach ? Should it be a tasks.json file that each time runs "$tsc-watch", launch the web site in Node and opens Chrome ?
I started with this tasks.json file :
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc-watch"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Chrome",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
},
"args": ["./index.htm"],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Then, VSCode created a launch.json file but I'm not sure why and where it fits in the picture:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
Would you be able to help me understand what I am doing wrong here and what I need to simply debug my application in VSCode as I would pressing F5 in VSStudio.
Thank you for any help,
Claude
It looks like you're trying to create the entire build-chain and configuration yourself. I recommend starting with a tool that handles the initial bootstrapping for you. For exampe, use the vue-cli tool to bootstrap a vue.js project with TypeScript. While it may include a little bit of spin-up in understanding vue.js, the vue-cli tool lets you select options (e.g. TypeScript) and auto-generates a project for you. Then, just open the newly created folder in Visual Studio Code and start playing around.
Once you get a feel for how it all ties together, you can add VSCode specific tasks, start modifying configurations, etc.
There are a number of good tutorials on vue.js and, in practice, you'll probably want to leverage a front-end framework when building any real application anyway.
See the following links for tutorials and more information:
vue-cli
vue.js
With a node.js project, I've added eslint-plugin-security and it is giving a lot of warnings for code in my test/spec files (using mochajs). Since the test code won't be running in production, these don't seem as useful as they do in the project's actual code. (A lot of Generic Object Injection Sink warnings )
Is there a way to have the security plugin ignore certain files other than putting /* eslint-disable */ at the top of every spec file?
The best way I found to deal with this case is based on this answer.
You can override parts of your eslint file in a subfolder. In my case I'm disabling problematic rules from a jest plugin inside my e2e tests folder. Example .eslintrc.js in /e2e-tests/ :
module.exports = {
overrides: [
{
files: ["*.spec.js"],
rules: {
"jest/valid-expect": 0
}
}
]
};
There is three way to ignore files or folders:
1. Creating a .eslintignore on your project root folder with the thing you want to ignore:
**/*.js
2. Using eslint cli & the --ignore-path to specify another file where your ignore rules will be located
eslint --ignore-path .jshintignore file.js
3. Using your package.json
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"env": {
"browser": true,
"node": true
}
},
"eslintIgnore": ["*.spec.ts", "world.js"]
}
Official Documentation
On my side, I had issue with Intellij IDEA where eslint was checking files in a folder only dedicated to Typescript (+tslint) which was a pain, so I've picked solution 3.
I am trying to add Bootstrap 4 to Aurelia. I can only get the CSS to work but the bootstrap.js requires Tether and I can't get it included, since I keep getting this error in the console:
Bootstrap tooltips require Tether
I tried something along this
"jquery",
"Tether",
{
"name": "tether",
"path": "../node_modules/tether/dist",
"main": "js/tether.min",
"exports": "Tether",
"resources": [
"css/tether.css"
]
},
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.min",
"deps": ["tether", "jquery"],
"exports": "$",
"resources": [
"css/bootstrap.css"
]
},
It does bundle, but it's still complaining about the missing Tether.
I read on another stack answer that I have to makeTetheravailable globally which could be done viarequirejs.config.js` with this
define(['lib/tether.min'], function(tether) {
window.Tether = tether;
});
but there's no such config with Aurelia.
After some more time spent on this, I believe that I came up with something working. I don't see anymore errors and I am now able to use Bootstrap tooltip, so I will assume this is the working solution.
All the changes were made inside the aurelia.json configuration file, as the following:
"prepend": [
"node_modules/bluebird/js/browser/bluebird.core.js",
"node_modules/tether/dist/js/tether.min.js",
"scripts/require.js"
],
"dependencies": [
...
"aurelia-templating-binding",
"jquery",
"tether",
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.min",
"deps": ["jquery", "tether"],
"exports": "$",
"resources": [
"css/bootstrap.css"
]
},
...
So basically, I just had to add it to the prepend to get it working. Also note that adding tether inside the deps[] array has no effect (probably because Tether is now global with the prepend), but I like to see it there as a reminder that it's a dependencies anyway.
EDIT
As mentioned by #Paul-Sebastian, it's probably better to remove tether from showing up in the deps of Bootstrap to remove possibility of double inclusion. Basically this is the updated code:
"tether",
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.min",
"deps": ["jquery"],
"exports": "$",
"resources": [
"css/bootstrap.css"
]
},
EDIT #2
There is now also an append section that just got added to Aurelia-CLI to help with Legacy Library with Plugins. The section reads as the following:
A Very Stubborn Legacy Library With Plugins
Some legacy libraries may support plugins which you also want included in your bundle. In some cases these plugins depend on a
global object defined by the main library, so it is important that the
plugins exist later in the bundle than the main library scripts. These
plugins can go in the append section, which works exactly the same
as the prepend section but the scripts are appended to the end of
the bundle, after all other items. Like the prepend section all items
are relative to the project folder, not the src.