Skip to content

Adjust imports in scripts and webpack directories#4739

Open
alanorth wants to merge 12 commits intoDSpace:mainfrom
alanorth:node-prefix-imports
Open

Adjust imports in scripts and webpack directories#4739
alanorth wants to merge 12 commits intoDSpace:mainfrom
alanorth:node-prefix-imports

Conversation

@alanorth
Copy link
Copy Markdown
Contributor

@alanorth alanorth commented Sep 30, 2025

Related

Description

A handful of import- and console.log-related fixes were missed in the scripts and webpack directories due to the lint configuration in angular.json not considering them.

Instructions for Reviewers

Please add a more detailed description of the changes made by your PR. At a minimum, providing a bulleted list of changes in your PR is helpful to reviewers.

List of changes in this PR:

  • First, update lint configuration in angular.json to consider scripts and webpack directories
  • Second, run npm run lint-fix to automatically fix as many errors as possible
  • Third, add node: prefix to several imports of internal Node.js APIs (fs and path) and scope to methods we use
  • Fourth, disable eslint for copy-webpack-plugin because it doesn't support ES Module imports
  • Fifth, remove unused sass and lodash imports
  • Sixth, rework JSON5, commander, and cli-progress imports to use scoped ES Module imports
  • Seventh, use scoped imports for lodash modules
  • Eighth, replace console.log() usage with console.info()

Include guidance for how to test or review your PR. This may include: steps to reproduce a bug, screenshots or description of a new feature, or reasons behind specific changes.

Make sure the dev and prod builds are successful.

Make sure i18n scripts work:

$ npm run merge-i18n -- -s src/themes/custom/assets/i18n
$ npm run sync-i18n

Make sure all tests in CI pass.

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@alanorth alanorth added code task 1 APPROVAL pull request only requires a single approval to merge port to dspace-9_x This PR needs to be ported to `dspace-9_x` branch for next bug-fix release labels Sep 30, 2025
@alanorth alanorth added this to the 10.0 milestone Sep 30, 2025
@alanorth alanorth added the dependencies Pull requests that update a dependency file label Sep 30, 2025
@tdonohue tdonohue moved this to 🙋 Needs Reviewers Assigned in DSpace 10.0 Release Sep 30, 2025
@alanorth alanorth force-pushed the node-prefix-imports branch 2 times, most recently from d76f3da to 0f1295b Compare October 1, 2025 10:05
@alanorth alanorth force-pushed the node-prefix-imports branch from 0f1295b to 254ea5b Compare November 10, 2025 12:09
@tdonohue tdonohue self-requested a review November 10, 2025 15:46
@github-actions
Copy link
Copy Markdown

Hi @alanorth,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@nwoodward
Copy link
Copy Markdown
Contributor

@alanorth I'm sorry I didn't look at this sooner. It's mainly formatting and prefixes. Can you fix the conflicts and I'll review it?

@nwoodward nwoodward self-requested a review January 23, 2026 22:51
Copy link
Copy Markdown
Member

@alexandrevryghem alexandrevryghem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thnx @alanorth for this PR! I already took a quick look at the changed files and it looks great. I did add one small inline suggestion, but I will do a full review once those conflicts are resolved

Comment thread webpack/helpers.ts Outdated
@github-project-automation github-project-automation Bot moved this from 🙋 Needs Reviewers Assigned to 👀 Under Review in DSpace 10.0 Release Apr 3, 2026
Comment thread webpack/webpack.mirador.config.ts Outdated
@alanorth
Copy link
Copy Markdown
Contributor Author

The scope of this PR has changed because main updated the linting rules. Now there are more things to fix in the scripts and webpack directories. I am working on it.

@alanorth alanorth changed the title Add node: prefix to internal imports Adjust imports in scripts and webpack directories Apr 17, 2026
@alanorth alanorth force-pushed the node-prefix-imports branch from cce3c97 to 452f0e2 Compare April 17, 2026 19:16
@alanorth
Copy link
Copy Markdown
Contributor Author

alanorth commented Apr 18, 2026

I'm not sure why the lodash import rule is triggering, since we are importing individual methods:

import {
  isEmpty,
  isEqual,
} from 'lodash';

Must be something subtle about the plugin's configuration? @alexandrevryghem?

@alexandrevryghem
Copy link
Copy Markdown
Member

@alanorth: It's part of the lodash/import-scope rule. The correct usage is:

import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';

@alanorth alanorth force-pushed the node-prefix-imports branch from f863722 to 4f26e4e Compare April 18, 2026 17:49
@alanorth
Copy link
Copy Markdown
Contributor Author

alanorth commented Apr 18, 2026

Thanks @alexandrevryghem. I've updated it.

For what it's worth, I see our configuration of lodash/import-scope uses the "method" import style:

import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';

While this style would be the "member" style:

import {
  isEmpty,
  isEqual,
} from 'lodash';

All of our other imports in dspace-angular use the latter style.

P.S. removing the port to dspace-9_x tag since this ended up being more changes than I thought (and for example, the console.log() linting changes were not ported there).

@alanorth alanorth removed the port to dspace-9_x This PR needs to be ported to `dspace-9_x` branch for next bug-fix release label Apr 18, 2026
@alanorth alanorth marked this pull request as ready for review April 18, 2026 18:02
@alanorth
Copy link
Copy Markdown
Contributor Author

Something strange going on with tests in CI. Closing and re-opening.

@alanorth alanorth closed this Apr 20, 2026
@github-project-automation github-project-automation Bot moved this from 👀 Under Review to ✅ Done in DSpace 10.0 Release Apr 20, 2026
@alanorth alanorth reopened this Apr 20, 2026
alanorth added 12 commits April 22, 2026 09:50
Include the scripts and webpack directories in linting.
Automatically fix most lint errors.
Don't use require-style imports and scope some imports of path and
fs so we only import methods we are using.
Disable the no-require-imports rule for copy-webpack-plugin because
it does not support ES Module style imports.
Don't use a require-style import, and only import the methods we
are actually using.
Don't use require-style imports, and only import the methods that
we actually use instead of the whole module. Also, we need to use
a different syntax to access the parsed opts after this for some
reason.
Don't use require-style imports, and scope the imports to only the
methods we are using.
Don't use require-style imports, and only import the methods that
we are actually using.
Disable eslint rule for require-style imports here since this isn't
importing a Node.js module, but a command line argument.
@alanorth alanorth force-pushed the node-prefix-imports branch from 4f26e4e to 04eb514 Compare April 22, 2026 06:50
@alanorth
Copy link
Copy Markdown
Contributor Author

I'm not sure why this is failing e2e tests in CI. I see some error early in the logs after the e2e tests start:

2026-04-22T07:09:03.5171951Z 
2026-04-22T07:09:03.5287942Z Environment extended with app config
2026-04-22T07:09:03.5289193Z 
2026-04-22T07:09:03.5290717Z dspace-angular
2026-04-22T07:09:03.5293112Z Version: 10.0.0-next
2026-04-22T07:09:03.5293526Z Environment: Production
2026-04-22T07:09:03.5293772Z 
2026-04-22T07:09:03.5319495Z [HPM] Proxy created: /  -> http://127.0.0.1:8080/server/sitemaps
2026-04-22T07:09:03.5323004Z [HPM] Proxy created: /  -> http://127.0.0.1:8080/server
2026-04-22T07:09:03.5629110Z [07:09:03 GMT+0000 (Coordinated Universal Time)] Listening at http://127.0.0.1:4000
2026-04-22T07:09:04.2817375Z ERROR SyntaxError: Expected property name or '}' in JSON at position 1
2026-04-22T07:09:04.2817879Z     at JSON.parse (<anonymous>)
2026-04-22T07:09:04.2818547Z     at TranslateServerLoader.getTranslation (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:7801704)
2026-04-22T07:09:04.2819540Z     at TranslateService2.loadAndCompileTranslations (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:5256381)
2026-04-22T07:09:04.2820699Z     at TranslateService2.loadOrExtendLanguage (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:5256092)
2026-04-22T07:09:04.2821932Z     at TranslateService2.use (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:5255608)
2026-04-22T07:09:04.2822681Z     at Object.next (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:591711)
2026-04-22T07:09:04.2823423Z     at ConsumerObserver2.next (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:3336710)
2026-04-22T07:09:04.2824246Z     at SafeSubscriber2.Subscriber2._next (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:3336072)
2026-04-22T07:09:04.2825101Z     at SafeSubscriber2.Subscriber2.next (/home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:3335509)
2026-04-22T07:09:04.2825813Z     at /home/runner/work/dspace-angular/dspace-angular/dist/server/main.js:1:3419624

This is followed by a bunch of other errors about reading undefined from a pipe. I haven't figured out why this is happening yet. I suppose it is all due to the first JSON parsing error, seemingly in the translation service?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 APPROVAL pull request only requires a single approval to merge code task dependencies Pull requests that update a dependency file

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants