[Unicode]   Common Locale Data Repository : Bug Tracking Home | Site Map | Search
 
Modify

CLDR Ticket #10892(new unknown)

Opened 3 months ago

Last modified 2 months ago

JSON npm packages are not valid modules

Reported by: kalashnikov@… Owned by: anybody
Component: json Data Locale:
Phase: dsub Review:
Weeks: Data Xpath:
Xref:

Description

I raised this issue in Github a while ago, but the issue tracker was quietly nuked and I never got a response. Judging by how this is still the case I assume the issue was just swept under the rug.

All of the npm packages are not valid modules (see https://docs.npmjs.com/all#what-is-a-module-) which makes it impossible to require or more importantly to require.resolve the path to them.

require('cldr-dates-modern')
Error: Cannot find module 'cldr-dates-modern'

npm has a complex and non-deterministic folder/package structure for dependencies and it's practically impossible to know the path to package contents. require.resolve solves this problem, but it only operates with modules.

As the CLDR JSON npm packages are nothing but json files it's important to be able to get the path to them to be able to read and parse the CLDR data.

Currently in my application I have a postinstall script workaround that tries to find the modules and touch index.js in them.

I believe all of the packages should be made valid modules so that developers can rely on their locations.

There are two ways to achieve that:

  1. Place a file name index.js in package root folder.
  2. Place a file with any other name anywhere within module structure and declare it as main in package.json.
  3. Add a postinstall hook that generates the file.

I think the best approach would be to place index.js into main folder and add "main": "main" to package.json.

The file itself can be simply empty or it can contain some useful code so that requiring the module actually provides access to the data and makes using CLDR JSON much easier.

Attachments

Change History

comment:1 Changed 2 months ago by srl

I raised this issue in Github a while ago, but the issue tracker was quietly nuked and I never got a response. Judging by how this is still the case I assume the issue was just swept under the rug.

This is the right place to raise issues (please include a URL such as https://github.com/unicode-cldr/cldr-dates-modern ) . I don't think the issue was necessarily swept under the rug, a separate issue tracker in github was a mistake. The readmes point to https://github.com/unicode-cldr/cldr-json#bug-reports which says to not use Github issues for such bugs.

All of the NPM packages are not valid modules

One could use https://www.npmjs.com/package/cldr-data

but I was also able to do this, can you try it:

$ npm i cldr-dates-modern
+ cldr-dates-modern@32.0.0
added 1 package in 1.862s
$ node
> require('cldr-dates-modern/main/zu/dateFields.json')
{ main: { zu: { identity: [Object], dates: [Object] } } }
View

Add a comment

Modify Ticket

Action
as new
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.