Skip to content

Commit

Permalink
feat: Convert to ESM (#286)
Browse files Browse the repository at this point in the history
* feat: Convert to ESM

BREAKING CHANGE: Convert from CommonJS module to ESM

* fix: Set type to be module

Co-authored-by: Trygve Lie <trygve.lie@finn.no>
  • Loading branch information
trygve-lie and Trygve Lie authored May 10, 2021
1 parent 4c2e4f3 commit 7824568
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 98 deletions.
6 changes: 4 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tap-snapshots/
coverage/
coverage
tap-snapshots
benchmark/
example/
dist/
28 changes: 15 additions & 13 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"root": true,
"extends": ["airbnb-base", "prettier"],
"overrides": [
{
"files": "__tests__/**/*",
"env": {
"jest": true
}
}
],
"plugins": ["prettier"],
"extends": ["airbnb-base", "prettier"],
"plugins": ["prettier"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"rules": {
"strict": [0, "global"],
"import/prefer-default-export": "off",
"class-methods-use-this": [0],
"no-param-reassign": [0]
"lines-between-class-members": [0],
"import/extensions": ["error", {
"js": "ignorePackages"
}
]
}
}


4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- name: npm install
run: |
npm install
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- name: npm install
run: |
npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [12.x, 14.x]
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ node_modules/**/*
tmp/**/*
.idea
.idea/**/*
coverage
coverage
dist
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
38 changes: 20 additions & 18 deletions lib/layout.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
/* eslint-disable consistent-return */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-param-reassign */

'use strict';

const {
import {
HttpIncoming,
template,
isFunction,
pathnameBuilder,
uriIsRelative,
AssetCss,
AssetJs,
} = require('@podium/utils');
const { validate } = require('@podium/schemas');
const Context = require('@podium/context');
const Metrics = require('@metrics/client');
const objobj = require('objobj');
const Client = require('@podium/client');
const abslog = require('abslog');
const Proxy = require('@podium/proxy');
const pkg = require('../package.json');
} from '@podium/utils';
import * as schema from '@podium/schemas';
import Context from '@podium/context';
import Metrics from '@metrics/client';
import objobj from 'objobj';
import Client from '@podium/client';
import abslog from 'abslog';
import Proxy from '@podium/proxy';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';

const currentDirectory = dirname(fileURLToPath(import.meta.url));
const pkgJson = fs.readFileSync(join(currentDirectory, '../package.json'), 'utf-8');
const pkg = JSON.parse(pkgJson);

const _pathname = Symbol('_pathname');
const _sanitize = Symbol('_sanitize');
const _addCssAsset = Symbol('_addCssAsset');
const _addJsAsset = Symbol('_addJsAsset');

const PodiumLayout = class PodiumLayout {
/* istanbul ignore next */
export default class PodiumLayout {
constructor({
name = '',
pathname = '',
Expand All @@ -37,12 +41,12 @@ const PodiumLayout = class PodiumLayout {
client = {},
proxy = {},
} = {}) {
if (validate.name(name).error)
if (schema.name(name).error)
throw new Error(
`The value, "${name}", for the required argument "name" on the Layout constructor is not defined or not valid.`,
);

if (validate.uri(pathname).error)
if (schema.uri(pathname).error)
throw new Error(
`The value, "${pathname}", for the required argument "pathname" on the Layout constructor is not defined or not valid.`,
);
Expand Down Expand Up @@ -249,5 +253,3 @@ const PodiumLayout = class PodiumLayout {
return uri;
}
};

module.exports = PodiumLayout;
38 changes: 23 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@podium/layout",
"version": "5.0.0-next.5",
"type": "module",
"description": "Module for composing full page layouts out of page fragments in a micro frontend architecture.",
"main": "lib/layout.js",
"license": "MIT",
"keywords": [
"micro services",
Expand All @@ -24,49 +24,57 @@
"index.d.ts",
"README.md",
"LICENSE",
"dist",
"lib"
],
"main": "./dist/layout.js",
"exports": {
"require": "./dist/layout.js",
"import": "./lib/layout.js"
},
"types": "index.d.ts",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test": "tap --no-check-coverage",
"test:snapshots": "tap --snapshot --no-check-coverage",
"lint:format": "eslint --fix .",
"precommit": "lint-staged"
"prepare": "npm run -s build",
"build": "rollup -c"
},
"dependencies": {
"@metrics/client": "2.5.0",
"@podium/client": "5.0.0-next.4",
"@podium/context": "5.0.0-next.3",
"@podium/proxy": "5.0.0-next.2",
"@podium/schemas": "5.0.0-next.1",
"@podium/utils": "5.0.0-next.2",
"@podium/client": "5.0.0-next.7",
"@podium/context": "5.0.0-next.5",
"@podium/proxy": "5.0.0-next.5",
"@podium/schemas": "5.0.0-next.4",
"@podium/utils": "5.0.0-next.6",
"abslog": "2.4.0",
"ajv": "8.3.0",
"lodash.merge": "4.6.2",
"objobj": "1.0.0",
"ajv": "8.3.0"
"objobj": "1.0.0"
},
"devDependencies": {
"@podium/podlet": "4.4.21",
"@podium/podlet": "5.0.0-next.4",
"@podium/test-utils": "2.3.0",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/commit-analyzer": "8.0.1",
"@semantic-release/git": "9.0.0",
"@semantic-release/github": "7.2.1",
"@semantic-release/npm": "7.1.1",
"@semantic-release/github": "7.2.3",
"@semantic-release/npm": "7.1.3",
"@semantic-release/release-notes-generator": "9.0.2",
"eslint": "7.25.0",
"babel-eslint": "10.1.0",
"eslint": "7.26.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-prettier": "3.4.0",
"express": "4.17.1",
"hbs": "4.1.2",
"prettier": "2.2.1",
"rollup": "2.46.0",
"semantic-release": "17.4.2",
"stoppable": "1.1.0",
"supertest": "6.1.3",
"tap": "15.0.6"
"tap": "15.0.9"
}
}
File renamed without changes.
25 changes: 25 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
input: 'lib/layout.js',
external: [
'@podium/schemas',
'@podium/context',
'@metrics/client',
'@podium/client',
'@podium/utils',
'@podium/proxy',
'@podium/utils',
'abslog',
'objobj',
'path',
'url',
'fs',
],
output: [
{
exports: 'auto',
format: 'cjs',
dir: 'dist/',
preserveModules: true,
}
],
};
Loading

0 comments on commit 7824568

Please sign in to comment.