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
Include the scripts and webpack directories in linting.
Automatically fix most lint errors.
@alanorth alanorth force-pushed the node-prefix-imports branch from 254ea5b to ff316ff Compare April 17, 2026 07:02
@alanorth alanorth marked this pull request as draft April 17, 2026 07:07
@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.

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.
@alanorth alanorth changed the title Add node: prefix to internal imports Adjust imports in scripts and webpack directories Apr 17, 2026
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.
@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';

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 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
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: 👀 Under Review

Development

Successfully merging this pull request may close these issues.

4 participants