Skip to content
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

[BREAKING] Transform module to ESM #472

Merged
merged 53 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
974282e
Update testing dependencies for ESM, fix ESLint / JSDoc
matz3 Sep 14, 2022
20e0ffd
Transform lib/
matz3 Sep 14, 2022
9d11bcc
Transform test/
matz3 Sep 14, 2022
0cf4cae
Start fixing tests
matz3 Sep 15, 2022
d48d6de
fix ProjectBuilder.js
flovogt Sep 15, 2022
774cd31
Start fixing validation tests
matz3 Sep 15, 2022
263123e
Fix validation tests
matz3 Sep 15, 2022
6240a18
Fix ui5Framework tests
matz3 Sep 15, 2022
bd08478
Fix specifiction tests
matz3 Sep 15, 2022
e735599
fix: test/lib/build/TaskRunner.js
flovogt Sep 15, 2022
a793102
wip builder and graph
flovogt Sep 16, 2022
c815bb5
continue build and graph
flovogt Sep 16, 2022
ca4b27a
wip
flovogt Sep 16, 2022
55f4fe3
Specifictation: Properly test create factory
matz3 Sep 19, 2022
7e538d4
Fix Library specification tests
matz3 Sep 20, 2022
8c684a0
Fix ui5Framework.integration.js test
matz3 Sep 20, 2022
9f01f20
Fix more tests
matz3 Sep 20, 2022
c5da914
Continue fixing TaskRunner
matz3 Sep 20, 2022
17cd247
Fix TaskRunner test
matz3 Sep 21, 2022
a121a3c
Fix build/helpers/createBuildManifest
matz3 Sep 21, 2022
2958e11
Fix composeProjectList test and add missing test case
matz3 Sep 21, 2022
de83d20
Fix more tests
matz3 Sep 21, 2022
73208b3
Fix all tests
matz3 Sep 21, 2022
7bcec61
Define package exports
matz3 Sep 27, 2022
a3c1f81
Fix jsdoc build
matz3 Sep 27, 2022
aabf57b
Start updating JSDoc for ESM imports
matz3 Sep 27, 2022
0e70725
Export generateProjectGraph as graph API
matz3 Sep 30, 2022
341b079
Adopt graph.js to use named exports with new names
matz3 Sep 30, 2022
684cd86
Move graph.js to graph dir
matz3 Sep 30, 2022
7bdddce
Adjust fs named imports
flovogt Sep 30, 2022
57d9ccc
use internal subpath
flovogt Sep 30, 2022
617c47f
fix standardTask handlinh when no ones are given
flovogt Sep 30, 2022
d69d431
fix ProjectGraph
flovogt Sep 30, 2022
e38e4cd
Update ESLint / JSDoc
matz3 Oct 5, 2022
ad29f51
Update API usage / tests
matz3 Oct 5, 2022
7a2d8de
Fix / update tests
matz3 Oct 5, 2022
749a56c
Adapt to new async APIs
matz3 Oct 6, 2022
27fa989
TaskRunner: standardTasks must be provided
matz3 Oct 6, 2022
a6928c5
Update test names
matz3 Oct 7, 2022
3b7b6fc
Ehance tests for CJS/ESM extensions
RandomByte Oct 7, 2022
4f4e5b8
jsdoc: part1
flovogt Oct 10, 2022
e513938
JSDoc comments
d3xter666 Oct 12, 2022
30b93ea
JSDoc: Change notations from . to /
d3xter666 Oct 12, 2022
3513550
JSDoc: Make annotations to modules mappable for jsdoc
d3xter666 Oct 13, 2022
2a6496d
JSDOC: build,specifications and smaller fixes
flovogt Oct 13, 2022
90e3473
JSDoc: fix build,graph
flovogt Oct 13, 2022
b76bbfe
JSDoc: enable jsdoc plugin
flovogt Oct 13, 2022
f2e7e83
JSDoc: smaller fixes
flovogt Oct 13, 2022
6f735b8
fix 'fs/resourceFactory imports'
flovogt Oct 13, 2022
c9b44bd
fix: add missing await
flovogt Oct 18, 2022
c6d9c0f
code smells and smaller refactorings
flovogt Oct 24, 2022
60898d4
Temporary use @ui5/builder esm branch
flovogt Oct 24, 2022
8ec6c9a
fix imports for windows
flovogt Oct 24, 2022
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
6 changes: 5 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
"parserOptions": {
"sourceType": "module",
},
"env": {
"node": true,
"es2021": true
Expand Down Expand Up @@ -73,7 +76,8 @@ module.exports = {
"settings": {
"jsdoc": {
"tagNamePreference": {
"return": "returns"
"return": "returns",
"augments": "extends"
}
}
},
Expand Down
72 changes: 0 additions & 72 deletions index.js

This file was deleted.

9 changes: 9 additions & 0 deletions jsdoc-plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* This plugin fixes unexpected JSDoc behavior that prevents us from using types that start with an at-sign (@).
* JSDoc doesn't see "{@" as a valid type expression, probably as there's also {@link ...}.
*/
exports.handlers = {
jsdocCommentFound: function(e) {
e.comment = e.comment.replace(/{@ui5\//g, "{ @ui5/");
}
};
13 changes: 0 additions & 13 deletions jsdoc-plugin.js

This file was deleted.

4 changes: 2 additions & 2 deletions jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"allowUnknownTags": false
},
"source": {
"include": ["README.md", "index.js"],
"include": ["README.md"],
"includePattern": ".+\\.js$",
"excludePattern": "(node_modules(\\\\|/))"
},
"plugins": [
"./jsdoc-plugin"
"./jsdoc-plugin.cjs"
],
"opts": {
"encoding": "utf8",
Expand Down
72 changes: 42 additions & 30 deletions lib/build/ProjectBuilder.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
const {promisify} = require("util");
const rimraf = promisify(require("rimraf"));
const resourceFactory = require("@ui5/fs").resourceFactory;
const log = require("@ui5/logger").getGroupLogger("build");
const composeProjectList = require("./helpers/composeProjectList");
const BuildContext = require("./helpers/BuildContext");

import {promisify} from "node:util";
import rimraf from "rimraf";
const rimrafp = promisify(rimraf);
import * as resourceFactory from "@ui5/fs/resourceFactory";
import logger from "@ui5/logger";
const log = logger.getGroupLogger("build");
import composeProjectList from "./helpers/composeProjectList.js";
import BuildContext from "./helpers/BuildContext.js";
import prettyHrtime from "pretty-hrtime";

/**
* @public
* @class
* @alias @ui5/project/build/ProjectBuilder
*/
class ProjectBuilder {
/**
* Build Configuration
*
* @public
* @typedef {object} BuildConfiguration
* @param {boolean} [selfContained=false] Flag to activate self contained build
* @param {boolean} [cssVariables=false] Flag to activate CSS variables generation
* @param {boolean} [jsdoc=false] Flag to activate JSDoc build
* @param {boolean} [createBuildManifest=false]
* @typedef {object} @ui5/project/build/ProjectBuilder~BuildConfiguration
* @property {boolean} [selfContained=false] Flag to activate self contained build
* @property {boolean} [cssVariables=false] Flag to activate CSS variables generation
* @property {boolean} [jsdoc=false] Flag to activate JSDoc build
* @property {boolean} [createBuildManifest=false]
* Whether to create a build manifest file for the root project.
* This is currently only supported for projects of type 'library' and 'theme-library'
* @param {Array.<string>} [includedTasks=[]] List of tasks to be included
* @param {Array.<string>} [excludedTasks=[]] List of tasks to be excluded.
* @property {Array.<string>} [includedTasks=[]] List of tasks to be included
* @property {Array.<string>} [excludedTasks=[]] List of tasks to be excluded.
* If the wildcard '*' is provided, only the included tasks will be executed.
*/

/**
* Executes a project build, including all necessary or requested dependencies
*
* @public
* @param {module:@ui5/project.graph.ProjectGraph} graph Project graph
* @param {module:@ui5/builder.tasks.taskRepository} taskRepository Task Repository module
* @param {module:@ui5/project.build.ProjectBuilder.BuildConfiguration} [buildConfig] Build configuration
* @param {@ui5/project/graph/ProjectGraph} graph Project graph
* @param {@ui5/builder/tasks/taskRepository} taskRepository Task Repository module
* @param {@ui5/project/build/ProjectBuilder~BuildConfiguration} [buildConfig] Build configuration
*/
constructor(graph, taskRepository, buildConfig) {
if (!graph) {
Expand Down Expand Up @@ -93,7 +101,7 @@ class ProjectBuilder {
return filterProject(projectName);
});

const projectBuildContexts = this._createRequiredBuildContexts(requestedProjects);
const projectBuildContexts = await this._createRequiredBuildContexts(requestedProjects);
const cleanupSigHooks = this._registerCleanupSigHooks();
const fsTarget = resourceFactory.createAdapter({
fsBasePath: destPath,
Expand Down Expand Up @@ -147,7 +155,7 @@ class ProjectBuilder {

if (cleanDest) {
log.info(`Cleaning target directory...`);
await rimraf(destPath);
await rimrafp(destPath);
}
const startTime = process.hrtime();
try {
Expand Down Expand Up @@ -184,17 +192,18 @@ class ProjectBuilder {
}
}

_createRequiredBuildContexts(requestedProjects) {
async _createRequiredBuildContexts(requestedProjects) {
const allProjects = this._graph.getAllProjects();
const requiredProjects = new Set(allProjects.filter((project) => {
return requestedProjects.includes(project.getName());
}));

const projectBuildContexts = new Map();
requiredProjects.forEach((project) => {

for (const project of requiredProjects) {
const projectName = project.getName();
log.verbose(`Creating build context for project ${projectName}...`);
const projectBuildContext = this._buildContext.createProjectContext({
const projectBuildContext = await this._buildContext.createProjectContext({
project,
log
});
Expand All @@ -215,7 +224,8 @@ class ProjectBuilder {
requiredProjects.add(depProject);
});
}
});
}

return projectBuildContexts;
}

Expand Down Expand Up @@ -280,7 +290,7 @@ class ProjectBuilder {
// Ignore project itself
return;
}
readers.push(dep.getReader());
readers.push(await dep.getReader());
});

const dependencies = resourceFactory.createReaderCollection({
Expand All @@ -289,7 +299,7 @@ class ProjectBuilder {
});

await taskRunner.runTasks({
workspace: project.getWorkspace(),
workspace: await project.getWorkspace(),
dependencies,
});
}
Expand All @@ -298,14 +308,17 @@ class ProjectBuilder {
const project = projectBuildContext.getProject();
const taskUtil = projectBuildContext.getTaskUtil();
const buildConfig = this._buildContext.getBuildConfig();
const resources = await project.getReader({
const reader = await project.getReader({
// Force buildtime (=namespaced) style when writing with a build manifest
style: taskUtil.isRootProject() && buildConfig.createBuildManifest ? "buildtime" : "runtime"
}).byGlob("/**/*");
});
const resources = await reader.byGlob("/**/*");

if (taskUtil.isRootProject() && buildConfig.createBuildManifest) {
// Create and write a build manifest metadata file
const createBuildManifest = require("./helpers/createBuildManifest");
const {
default: createBuildManifest
} = await import("./helpers/createBuildManifest.js");
const metadata = await createBuildManifest(project, buildConfig);
await target.write(resourceFactory.createResource({
path: `/.ui5/build-manifest.json`,
Expand Down Expand Up @@ -383,10 +396,9 @@ class ProjectBuilder {
* @returns {string} Difference between now and the provided time array as formatted string
*/
_getElapsedTime(startTime) {
const prettyHrtime = require("pretty-hrtime");
const timeDiff = process.hrtime(startTime);
return prettyHrtime(timeDiff);
}
}

module.exports = ProjectBuilder;
export default ProjectBuilder;
Loading