Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Bug fixes for publishing and scripts cleanup (#1115)
Browse files Browse the repository at this point in the history
* reduce npm scripts

* remove dead code

* cleanup dead code

* exclude typescript from the published output

* fix typo

* upgrade ts-node

* integration fixes
  • Loading branch information
Denys Vuika authored May 27, 2021
1 parent 5263b65 commit 2ce6f00
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 161 deletions.
33 changes: 5 additions & 28 deletions .make-helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

let fs = require('fs-extra');
let path = require('path');
let klawSync = require('klaw-sync');
const fs = require('fs-extra');
const path = require('path');
const klawSync = require('klaw-sync');

function cleanSourceMapRoot(mapRoot, sourcesRoot) {
klawSync(mapRoot, {filter: (item) => item.path.endsWith('.js.map')})
Expand Down Expand Up @@ -32,34 +32,11 @@ function copySources(rootDir, packageDir, ignoreMissing) {
}
// Copy over the CommonJS files
fs.copySync(rootDir, packageDir);
fs.copySync('./LICENSE.txt', packageDir + 'LICENSE.txt');
fs.copySync('./README.md', packageDir + 'README.md');
}

// Create a file that exports the importTargets object
function createImportTargets(importTargets, targetName, targetDirectory) {
const importMap = {};
for (const x in importTargets) {
importMap['alfresco-js-api/' + x] = ('alfresco-js-api/' + targetName + importTargets[x]).replace(/\.js$/, '');
}

const outputData =
`
"use strict"
var path = require('path');
var dir = path.resolve(__dirname);
module.exports = function() {
return ${JSON.stringify(importMap, null, 4)};
}
`

fs.outputFileSync(targetDirectory + 'path-mapping.js', outputData);
fs.copySync('./LICENSE.txt', `${packageDir}/LICENSE.txt`);
fs.copySync('./README.md', `${packageDir}/README.md`);
}

module.exports = {
copySources,
createImportTargets,
cleanSourceMapRoot
}
104 changes: 27 additions & 77 deletions .make-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,22 @@ const fs = require('fs-extra');
const mkdirp = require('mkdirp');
const path = require('path');
const klawSync = require('klaw-sync');
const { copySources, createImportTargets, cleanSourceMapRoot } = require('./.make-helpers');

let bo = null;
// Build Optimizer is not available on Node 4.x. Using a try/catch
// here to make sure the build passes on Travis using Node 4, but
// the NPM distribution will run through build-optimizer.
try {
bo = require('@angular-devkit/build-optimizer');
} catch (e) {}


const ROOT = 'dist/';
const CJS_ROOT = ROOT + 'cjs/';
const ESM5_FOR_ROLLUP_ROOT = ROOT + 'esm5_for_rollup/';
const ESM5_ROOT = ROOT + 'esm5/';
const ESM2015_ROOT = ROOT + 'esm2015/';
const UMD_ROOT = ROOT + 'global/';
const TYPE_ROOT = ROOT + 'typings/';
const PKG_ROOT = ROOT + 'package/';
const CJS_PKG = PKG_ROOT + '';
const ESM5_PKG = PKG_ROOT + '_esm5/';
const ESM2015_PKG = PKG_ROOT + '_esm2015/';
const UMD_PKG = PKG_ROOT + 'bundles/';
const SRC_ROOT_PKG = PKG_ROOT + 'src/';
const TYPE_PKG = PKG_ROOT + 'typings/';
const { copySources, cleanSourceMapRoot } = require('./.make-helpers');

const ROOT = 'dist';
const CJS_ROOT = `${ROOT}/cjs`;
const ESM5_FOR_ROLLUP_ROOT = `${ROOT}/esm5_for_rollup`;
const ESM5_ROOT = `${ROOT}/esm5`;
const ESM2015_ROOT = `${ROOT}/esm2015`;
const UMD_ROOT = `${ROOT}/global`;
const TYPE_ROOT = `${ROOT}/typings`;
const PKG_ROOT = `${ROOT}/package`;
const CJS_PKG = PKG_ROOT;
const ESM5_PKG = `${PKG_ROOT}/_esm5`;
const ESM2015_PKG = `${PKG_ROOT}/_esm2015`;
const UMD_PKG = `${PKG_ROOT}/bundles`;
const SRC_ROOT_PKG = `${PKG_ROOT}/src`;
const TYPE_PKG = `${PKG_ROOT}/typings`;

delete pkg.scripts;
delete pkg.devDependencies;
Expand All @@ -47,62 +38,21 @@ const rootPackageJson = {
es2015: './_esm2015/index.js'
};

// Execute build optimizer transforms on ESM5 files
klawSync(ESM5_ROOT, {
nodir: true,
filter: item => item.path.endsWith('.js')
})
.map(item => item.path.slice((`${__dirname}/${ESM5_ROOT}`).length))
.map(fileName => {
if (!bo) {
return fileName;
}
const fullPath = path.resolve(__dirname, ESM5_ROOT, fileName);
// The file won't exist when running build_test as we don't create the ESM5 sources
if (!fs.existsSync(fullPath)) {
return fileName;
}
const content = fs.readFileSync(fullPath).toString();
const transformed = bo.transformJavascript({
content,
getTransforms: [
bo.getPrefixClassesTransformer,
bo.getPrefixFunctionsTransformer,
bo.getFoldFileTransformer
]
});

fs.writeFileSync(fullPath, transformed.content);
return fileName;
});

const importTargets = {};

createImportTargets(importTargets, "_esm5/", ESM5_PKG);
createImportTargets(importTargets, "_esm2015/", ESM2015_PKG);

// Make the distribution folder
mkdirp.sync(PKG_ROOT);

// Copy over the sources
copySources('src/', SRC_ROOT_PKG);

copySources(CJS_ROOT, CJS_PKG);

// Clean up the source maps for CJS sources
cleanSourceMapRoot(PKG_ROOT, SRC_ROOT_PKG);

fs.copySync(TYPE_ROOT, TYPE_PKG);

copySources(ESM5_ROOT, ESM5_PKG, true);
cleanSourceMapRoot(ESM5_PKG, SRC_ROOT_PKG);

copySources(ESM2015_ROOT, ESM2015_PKG, true);
cleanSourceMapRoot(ESM2015_PKG, SRC_ROOT_PKG);

// Copy over tsconfig.json for bazel build support
fs.copySync('./tsconfig.base.json', PKG_ROOT + 'src/tsconfig.json');

fs.writeJsonSync(PKG_ROOT + 'package.json', rootPackageJson, {spaces: 2});

fs.copySync('./tsconfig.base.json', `${PKG_ROOT}/src/tsconfig.json`);
fs.writeJsonSync(`${PKG_ROOT}/package.json`, rootPackageJson, {spaces: 2});

if (fs.existsSync(UMD_ROOT)) {
fs.copySync(UMD_ROOT, UMD_PKG);
Expand Down Expand Up @@ -130,10 +80,10 @@ if (fs.existsSync(UMD_ROOT)) {
}

// remove umd.js/umd.d.ts files that are only needed for creation of the umd bundle
fs.removeSync(CJS_PKG + '/internal/umd.js');
fs.removeSync(CJS_PKG + '/internal/umd.js.map');
fs.removeSync(ESM5_PKG + '/internal/umd.js');
fs.removeSync(ESM5_PKG + '/internal/umd.js.map');
fs.removeSync(ESM2015_PKG + '/internal/umd.js');
fs.removeSync(ESM2015_PKG + '/internal/umd.js.map');
fs.removeSync(TYPE_PKG + '/internal/umd.d.ts');
fs.removeSync(`${CJS_PKG}/internal/umd.js`);
fs.removeSync(`${CJS_PKG}/internal/umd.js.map`);
fs.removeSync(`${ESM5_PKG}/internal/umd.js`);
fs.removeSync(`${ESM5_PKG}/internal/umd.js.map`);
fs.removeSync(`${ESM2015_PKG}/internal/umd.js`);
fs.removeSync(`${ESM2015_PKG}/internal/umd.js.map`);
fs.removeSync(`${TYPE_PKG}/internal/umd.d.ts`);
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ env:

install:
- npm install
- npm install -g ts-node

jobs:
include:
Expand Down
42 changes: 35 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 10 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@
"main": "index.js",
"typings": "index.d.ts",
"scripts": {
"build": "npm-run-all clean_dist build_cjs build_esm5 build_esm2015 build_esm5_for_rollup build_umd build_types generate_packages bundlesize-check",
"build_cjs": "npm-run-all clean_dist_cjs compile_dist_cjs",
"build_esm5": "npm-run-all clean_dist_esm5 compile_dist_esm5",
"build_esm5_for_rollup": "npm-run-all clean_dist_esm5_for_rollup compile_dist_esm5_for_rollup && mkdirp dist/esm5_for_rollup/node_modules",
"build_esm2015": "npm-run-all clean_dist_esm2015 compile_dist_esm2015",
"build_types": "npm-run-all clean_dist_types compile_dist_types",
"build_global": "npm-run-all clean_dist_global build_esm5_for_rollup && mkdirp ./dist/global && node ./tools/make-umd-bundle.js && npm run clean_dist_esm5_for_rollup",
"build_umd": "npm-run-all clean_dist_global && mkdirp ./dist/global && node ./tools/make-umd-bundle.js",
"clean_dist": "shx rm -rf ./dist",
"clean_dist_cjs": "shx rm -rf ./dist/cjs",
"clean_dist_esm5": "shx rm -rf ./dist/esm5",
"clean_dist_esm5_for_rollup": "shx rm -rf ./dist/esm5_for_rollup",
"clean_dist_esm2015": "shx rm -rf ./dist/esm2015",
"clean_dist_global": "shx rm -rf ./dist/global",
"clean_dist_types": "shx rm -rf ./dist/typings",
"compile_dist_cjs": "tsc -p ./tsconfig/tsconfig.cjs.json",
"compile_dist_esm5": "tsc -p ./tsconfig/tsconfig.esm5.json",
"compile_dist_esm2015": "tsc -p ./tsconfig/tsconfig.esm2015.json",
"compile_dist_esm5_for_rollup": "tsc -p ./tsconfig/tsconfig.esm5.rollup.json",
"compile_dist_types": "tsc -p ./tsconfig/tsconfig.types.json",
"build": "shx rm -rf ./dist && npm-run-all build_cjs build_esm5 build_esm2015 build_esm5_for_rollup build_umd build_types generate_packages bundlesize-check",
"build_cjs": "shx rm -rf ./dist/cjs && tsc -p ./tsconfig/tsconfig.cjs.json",
"build_esm5": "shx rm -rf ./dist/esm5 && tsc -p ./tsconfig/tsconfig.esm5.json",
"build_esm5_for_rollup": "shx rm -rf ./dist/esm5_for_rollup && tsc -p ./tsconfig/tsconfig.esm5.rollup.json && mkdirp dist/esm5_for_rollup/node_modules",
"build_esm2015": "shx rm -rf ./dist/esm2015 && tsc -p ./tsconfig/tsconfig.esm2015.json",
"build_types": "shx rm -rf ./dist/typings && tsc -p ./tsconfig/tsconfig.types.json",
"build_global": "shx rm -rf ./dist/global && npm run build_esm5_for_rollup && mkdirp ./dist/global && node ./tools/make-umd-bundle.js && npm run clean_dist_esm5_for_rollup",
"build_umd": "shx rm -rf ./dist/global && mkdirp ./dist/global && node ./tools/make-umd-bundle.js",
"generate_packages": "node .make-packages.js",
"prepublish": "shx rm -rf ./typings && npm run build",
"bundlesize-check": "bundlesize",
Expand Down Expand Up @@ -58,7 +46,7 @@
"@types/event-emitter": "^0.3.3",
"@types/minimatch": "^3.0.3",
"@types/mocha": "^8.0.0",
"@types/node": "^15.0.1",
"@types/node": "^15.6.1",
"@types/superagent": "^4.1.4",
"adf-tslint-rules": "0.0.7",
"bundlesize": "^0.18.1",
Expand All @@ -85,7 +73,7 @@
"shx": "^0.3.2",
"sinon": "^10.0.0",
"sinon-chai": "^3.3.0",
"ts-node": "^9.0.0",
"ts-node": "^10.0.0",
"tslint": "^6.1.2",
"tslint-etc": "^1.11.1",
"typescript": "^4.0.2",
Expand Down
10 changes: 5 additions & 5 deletions scripts/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ cat dist/package/package.json | grep version
mkdir -p $DIR/../test/integration/test-node/node_modules/@alfresco/js-api
cp -R $DIR/../dist/package/* $DIR/../test/integration/test-node/node_modules/@alfresco/js-api

ts-node ./test/integration/test-node/login-ecm.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
ts-node ./test/integration/test-node/upload-file.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
ts-node ./test/integration/test-node/login-bpmn.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
ts-node ./test/integration/test-node/login-sso.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
ts-node ./test/integration/test-node/node-content.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
npx ts-node ./test/integration/test-node/login-ecm.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
npx ts-node ./test/integration/test-node/upload-file.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
npx ts-node ./test/integration/test-node/login-bpmn.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
npx ts-node ./test/integration/test-node/login-sso.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
npx ts-node ./test/integration/test-node/node-content.ts --host $HOST -u "$USERNAME" -p "$PASSWORD" || exit 1
38 changes: 17 additions & 21 deletions test/integration/test-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceRoot": "../src",
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "CommonJS",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceRoot": "../src",
"target": "es5",
"typeRoots": ["node_modules/@types"],
"types": ["node"],
"lib": ["es2017", "dom"]
}
}

0 comments on commit 2ce6f00

Please sign in to comment.