> But there is no actual access enforcement for private modules. Because
> someone can do `require('pkgName/path/to/private/file')` to access
> internal modules. But that is a practice we can document to avoid as
> accessing modules
> in that fashion could break at any time. But I'm not sure if that
> practice is already used in any of our own code...

I believe there is an enforcement when the `exports` property is
defined in the `package.json`.

>From previous testing, if a user attempted to access a non-exported
module with the require statement
`require('pkgName/path/to/private/file')`, the following error appears:

```
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath
'./internal/someFile' is not defined by "exports" in
/Users/test/some-package/node_modules/some-library/package.json
```

If the `exports` property did not exist, then the require statement
worked.


On Tue, Nov 17, 2026, at 5:00 AM, Norman Breau via dev wrote:
> > Moving away from `rewire` may require us to export methods that were
> > previously private. If we want to maintain some separation between public
> > and internal APIs, we may need to investigate splitting these methods into
> > separate files and using npm's `exports` field in `package.json` to control
> > which entry points are publicly accessible. *This would need confirmation
> > if it is a viable solution.*
> 
> A practice I do in my own codebases (which is very class-orientated) is 
> that every module
> exports usually a single object or class definition.
> 
> But main module as defined in package.json is pointed to a "api.js" some 
> kind of index file that declares
> the public API. So a single file controls what is publicly exposed (in 
> otherwords you can access the symbol by a simple `require('pkgName')`). 
> Modules within the package can reference
> files, including the private internal modules by file structure path, 
> and that includes test code for attaching spies and such. This largely 
> avoids requiring a module like `rewire`.
> 
> But there is no actual access enforcement for private modules. Because 
> someone can do `require('pkgName/path/to/private/file')` to access 
> internal modules. But that is a practice we can document to avoid as 
> accessing modules
> in that fashion could break at any time. But I'm not sure if that 
> practice is already used in any of our own code...
> 
> On 2026-11-10 11:37 p.m., Bryan Ellis via dev wrote:
> > Node had introduced its built-in test runner `node:test`, as an
> > experimental feature in v18 but has since become a stable core feature in
> > v20.
> >
> > All of our packages should already meet the minimum Node version
> > requirement to use the built-in test runner. Infact, there might be an
> > increased minimum Node version to v22 in the upcoming major releases of our
> > packages, but will require a separate discussion thread.
> >
> > We have experimented with the new test runner in the following repositories
> > without encountering any issues:
> >
> > - https://github.com/apache/cordova-eslint
> > - https://github.com/apache/cordova-node-xcode
> > - https://github.com/apache/cordova-browser
> >
> > I will be opening a vote to finalize the migration of all our repositories
> > to the new built-in test runner and code coverage tooling.
> >
> > Even if the vote passes, I don't expect the migration to happen all at once
> > across every repository. Most, if not all, of our repositories rely heavily
> > on `rewire`, which could make the migration challenging.
> >
> > Moving away from `rewire` may require us to export methods that were
> > previously private. If we want to maintain some separation between public
> > and internal APIs, we may need to investigate splitting these methods into
> > separate files and using npm's `exports` field in `package.json` to control
> > which entry points are publicly accessible. *This would need confirmation
> > if it is a viable solution.*
> >
> > Overall, this change would effectively remove the reliance on the following
> > third-party npm dependencies and shrinks our package-lock.json.
> > - Jasmine
> > - NYC/C8
> > - Rewire
> >
> > Regards,
> > Bryan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 

Reply via email to