Skip to content

ES module support on Node 16 #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.16.1-alpine
FROM node:16-alpine

LABEL maintainer="madnificent@gmail.com"

Expand Down
6 changes: 4 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
["@babel/preset-env",
{
"targets": {
"node": 14
}
"node": 16,
"esmodules": true
},
"modules": false
}
],
["@babel/preset-typescript"]
Expand Down
8 changes: 4 additions & 4 deletions helpers/mu/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, errorHandler } from './server';
import sparql from './sparql';
import { v1 as uuidV1 } from 'uuid';
import { app, errorHandler } from "./server.js";
import sparql from "./sparql.js";
import { v1 as uuidV1 } from "uuid";

// generates a uuid
const uuid = uuidV1;
Expand All @@ -21,7 +21,7 @@ const mu = {
sparqlEscapeDateTime: sparql.sparqlEscapeDateTime,
sparqlEscapeBool: sparql.sparqlEscapeBool,
uuid,
errorHandler
errorHandler,
};

const SPARQL = mu.SPARQL,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "mu-javascript-template",
"version": "1.6.0",
"description": "Template for mu services written in JavaScript",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/mu-semtech/mu-javascript-template.git"
Expand All @@ -18,7 +19,7 @@
"@babel/preset-env": "^7.14.1",
"@babel/preset-typescript": "^7.16.7",
"babel-plugin-module-resolver": "4.1.0",
"body-parser": "~1.19.0",
"body-parser": "~1.20.0",
"coffeescript": "^2.6.1",
"env-var": "^7.0.0",
"express": "^4.17.1",
Expand Down
8 changes: 8 additions & 0 deletions transpile-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ fi
## mu helpers
cd /usr/src/processing/

## Need the babel config for building mu-package as well
cp /usr/src/app/package.json /usr/src/processing/helpers/mu/
cp /usr/src/app/babel.config.json /usr/src/processing/helpers/mu/

mkdir /usr/src/processing/built-mu
/usr/src/app/node_modules/.bin/babel \
/usr/src/processing/helpers/mu/ \
Expand All @@ -114,7 +118,11 @@ mkdir /usr/src/processing/built-mu

cp -R /usr/src/processing/built-mu /usr/src/build/node_modules/mu

## Put the package.json file in the mu package to make it a proper looking package (also for specifics like `"type": "module"`)
cp /usr/src/app/package.json /usr/src/build/node_modules/mu/

## Finish by putting the package.json file in the final build to make it a proper module
cp /usr/src/app/package.json /usr/src/build

## Clean temporary folders
##
Expand Down
33 changes: 16 additions & 17 deletions tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 14",

"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",
"allowJs": true,
"noEmit": true,

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"isolatedModules": true
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"compilerOptions": {
"lib": ["es2020"],
"module": "es2020",
"target": "es2020",
"allowJs": true,
"noEmit": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"isolatedModules": true
}
}
}