Skip to content

929 shift to npm approach map styles - #32

Merged
erictheise merged 26 commits into
stagingfrom
929-shift-to-npm-approach-map-styles
Mar 12, 2025
Merged

erictheise merged 26 commits into
stagingfrom
929-shift-to-npm-approach-map-styles

Conversation

@erictheise

Copy link
Copy Markdown
Contributor

OpenHistoricalMap/issues#929 was opened in response to the different approaches that have been taken to integrate map-styles into ohm-website, other OpenHistoricalMap projects, and non-OHM projects. This draft pull request does a few things:

  • runs an npm init, thus adding a package.json file
  • adds a prepare script that can be run manually during development and that runs automatically as part of npm publish
  • renames styles for internal consistency within map-styles and in ohm-website (e.g. entities known variously as main or original are now called historical to match the layer picker on the website)

The prepare script functions similarly to the update_map_styles.py script in ohm-deploy but is used earlier in the workflow allowing style versioning in ohm-website and openhistoricalmap-embed to be better understood.

A companion branch and PR will be opened in ohm-website momentarily.

@erictheise

Copy link
Copy Markdown
Contributor Author

Version 0.9.2 published at https://www.npmjs.com/package/@openhistoricalmap/map-styles. The styles are mature but the module isn't so I'd only bump to 1.0.0 once we're convinced the approach is sound and the integration with ohm-website works.

Comment thread LICENSE Resolved

@1ec5 1ec5 Feb 6, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

renames styles for internal consistency within map-styles and in ohm-website (e.g. entities known variously as main or original are now called historical to match the layer picker on the website)

Will each of the stylesheets’ public URLs change with respect to what we currently document? The last time we changed the URLs to these styles, it created quite a ripple effect: OpenHistoricalMap/issues#792 (comment). historical.json is a more descriptive name, and the new names of the other files are cleaner, but if these changes have any impact beyond this repository, we should save them for a different task separate from migrating to NPM.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll argue that migrating to NPM (and a halving of the cartography team) gives us a unique opportunity to do a bit of housecleaning as regards filenames. git got confused between the root level main directory and the branch of the same name, searching codebases for railway rather than rail narrows results considerably, and the one file that began with ohm suggested that it was unique in some way but I couldn't detect any reason why that would be so. The forEach loop in prepare expects the filenames to adhere to the naming in the styles array.

@1ec5 1ec5 Feb 6, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that these changes make sense. However, if the URL https://www.openhistoricalmap.org/map-styles/main/main.json breaks, then it’s a backwards-incompatible change and we need to plan accordingly. If you’re up for tackling this increased scope, then let’s track the various steps explicitly in a ticket. Since the last renaming, multiple third parties have adopted these styles, and there may be others we don’t know about.

It might be worth investigating whether we can put in symlinks or HTTP redirects to keep the old paths or URLs working for the time being as a deprecation strategy.

Comment thread package.json Resolved
@danrademacher

Copy link
Copy Markdown

We'll need to add documentation on how to use the new Node bits and pieces. A few questions to that end:

  1. Should we include an .nvmrc file to pin a node version so the first step is nvm use?
  2. Do I just do npm install and.. not sure what. Maybe npm run prepare?

I think that updates/creates dist/ohm.styles.js but not sure I even need to do that. Anyway, we'll want to document the publishing process so that Tim and Vanessa can weigh in on how it affects the existing workflows.

@danrademacher

danrademacher commented Feb 7, 2025 •

Copy link
Copy Markdown

Thinking about the redirects and style names:

From what I can tell, this PR combines all the map styles into a single output file, dist/ohm.styles.js.

Due to my own expertise limitations I'm having a hard time parsing the website PR against the style deploy script.

Question: After the map-styles and website PR are merged, will there be individual style JSON files similar to https://www.openhistoricalmap.org/map-styles/main/main.json for external providers to use (regardless of filenames, which as noted we'd need to solve with redirects)? Or just the one big JS with all the styles combined? So like https://www.openhistoricalmap.org/map-styles/historical.json or similar

Also, another aspect of the deploy script that I imagine we would need to retain is the swapping of staging vs production vtiles endpoints, so ultimately we might end up with a three interdependent PRs:

  • Map styles >> node
  • OHM website consume those
  • OHm deploy stop replacing files but still rewrite tile endpoints

@erictheise

erictheise commented Feb 7, 2025 •

Copy link
Copy Markdown
Contributor Author

From what I can tell, this PR combines all the map styles into a single output file, dist/ohm.styles.js.

Yes. That's essentially what currently happens with a Python script that runs as part of the deploy process. That script also replaces openhistoricalmap.github.io with the correct URL for staging or production so your point that it will be a three-way PR by the time it's ready to deploy is correct. The deploy script will continue swapping the URLs but it won't use openhistoricalmap.github.io as its anchor anymore. I'm under the impression we don't want anyone linking to or even thinking about hosting files from that domain anymore.

Question: After the map-styles and website PR are merged, will there be individual style JSON files similar to https://www.openhistoricalmap.org/map-styles/main/main.json for external providers to use (regardless of filenames, which as noted we'd need to solve with redirects)? Or just the one big JS with all the styles combined? So like https://www.openhistoricalmap.org/map-styles/historical.json or similar

A good question. The prepare script should populate /dist/ with styles that can be used individually, too. I was too focused on deployment as part of ohm-website but now it's pretty obvious that's the way to go.

Also, another aspect of the deploy script that I imagine we would need to retain is the swapping of staging vs production vtiles endpoints, so ultimately we might end up with a three interdependent PRs:

  • Map styles >> node
  • OHM website consume those
  • OHm deploy stop replacing files but still rewrite tile endpoints

This is correct.

@erictheise

Copy link
Copy Markdown
Contributor Author

We'll need to add documentation on how to use the new Node bits and pieces. A few questions to that end:

  1. Should we include an .nvmrc file to pin a node version so the first step is nvm use?

I'll do that. I don't think I'm using anything that doesn't have a long history with node but I use .nvmrcs in all my personal projects.

  1. Do I just do npm install and.. not sure what. Maybe npm run prepare?

I think that updates/creates dist/ohm.styles.js but not sure I even need to do that. Anyway, we'll want to document the publishing process so that Tim and Vanessa can weigh in on how it affects the existing workflows.

I'll write it up over the weekend at the latest so they can review it in time for the Tuesday all-hands. Documentation is a bit chicken-and-egg as I didn't want to start writing until I got some feedback, but the basics need to be documented in order to solicit feedback.

@1ec5

1ec5 commented Feb 7, 2025

Copy link
Copy Markdown
Member

The deploy script will continue swapping the URLs but it won't use openhistoricalmap.github.io as its anchor anymore. I'm under the impression we don't want anyone linking to or even thinking about hosting files from that domain anymore.

We definitely don’t want anyone to treat the GitHub Pages–deployed stylesheets as production stylesheets. Do we need to maintain those for testing during development, or should the embed site migrate to staging.openhistoricalmap.org?

@danrademacher

Copy link
Copy Markdown

We definitely don’t want anyone to treat the GitHub Pages–deployed stylesheets as production stylesheets. Do we need to maintain those for testing during development, or should the embed site migrate to staging.openhistoricalmap.org?

We still need somewhere that the carto team can test styles without having them already go through Rails deploy. So for now, we do need those GH Pages links at least for internal testing.

That said, Vanessa had asked me yesterday about building a local testing environment within the map-styles repo. That would be the best of all worlds, but I'm not sure what's involved. It could be a simple command to run that would start up a local instance of the embed code, pointed at local versions of the styles. Then the styling and testing environment would be self contained, and we could do away with GH Pages-hosted styles altogether.

That obv would merit a new ticket if the approach makes sense/is feasible.

@erictheise

Copy link
Copy Markdown
Contributor Author

Vanessa had asked me yesterday about building a local testing environment within the map-styles repo. That would be the best of all worlds, but I'm not sure what's involved. It could be a simple command to run that would start up a local instance of the embed code, pointed at local versions of the styles. Then the styling and testing environment would be self contained, and we could do away with GH Pages-hosted styles altogether.

The easiest thing may be to just set up a minimal express.js server in this repo that responds to npm test or some custom command. I haven't looked at embed recently but I feel like @1ec5 tinkers with new features there (isn't that where a Mercator-to-globe transition is running?) and it's not the vanilla environment we need. When the documentation-writing dust settles I was planning to look at embed as a consumer of the npm module.

@1ec5

1ec5 commented Feb 8, 2025 •

Copy link
Copy Markdown
Member

Ideally, Maputnik would have everything a designer would need to confidently visualize the style they’re designing. In an OHM context, that would require integrating the time slider into Maputnik: OpenHistoricalMap/issues#529. That entails building a new, resuable time slider UI: OpenHistoricalMap/issues#914.

I don’t think the embed site is much more complex than whatever we would produce as part of this repository. Before we can rely on this repo’s demo page again, it needs to incorporate almost everything in the embed site, especially date filtering. Back in November, we had to roll back a deployment of the styles because we had migrated them to expressions (OpenHistoricalMap/issues#775) but the time slider didn’t support expressions yet (OpenHistoricalMap/issues#855). We didn’t notice beforehand that date filtering would be broken, because this repo’s demo didn’t have date filtering at all.

The embed site has some other some bells and whistles, including the optional globe view and label localization. These features are already live in production, and we plan to incorporate them into the main site eventually (OpenHistoricalMap/issues#481 etc.). Since end users are already experiencing these features, anyone designing a style needs to have these features present too. Otherwise, they’d be designing in too sterile an environment. The only thing that probably isn’t essential for style design is the timelapse animations, which will eventually be moved to the time slider UI library anyways.

It could be a simple command to run that would start up a local instance of the embed code, pointed at local versions of the styles.

This is more or less implemented already:

  1. Check out openhistoricalmap-embed and stick a draft stylesheet in the dist/ folder.
  2. Replace this production URL with a relative path to the draft stylesheet.
  3. Run npm start.

We could add an additional option to load the style from an arbitrary location specified on the command line. Then map-styles could have openhistoricalmap-embed as a devDependency, cutting some steps out of the design workflow.

When the documentation-writing dust settles I was planning to look at embed as a consumer of the npm module.

It would make sense to turn map-styles into an NPM package and have openhistoricalmap-embed depend on map-styles. However, this wouldn’t eliminate the need to continue distributing the stylesheets from a stable public location. Every week brings another external developer directly depending on these styles.

@tsinn
tsinn marked this pull request as ready for review February 10, 2025 17:20
* new URL for historical style
* note that Github.io links should not be used in any external applications
* remove reference to Git-sha deploy method, which we're deprecating
* Add note about suing `nvm use`

@danrademacher danrademacher left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This overall looks good to me. One thing I noticed -- the dist artifacts are included in version control. Is that expected?

So when I ran npm build, I ended up with changes to dist/ohm-styles.js, which I didn't expect and didn't commit.

@erictheise

Copy link
Copy Markdown
Contributor Author

I neglected to run prepare after making sure all of Tim's recent layer changes had been brought over. That's why dist/ohm-styles.js changed for you. I've committed that now.

@erictheise
erictheise merged commit 8b120e6 into staging Mar 12, 2025
danrademacher pushed a commit to OpenHistoricalMap/openhistoricalmap-embed that referenced this pull request Mar 12, 2025
This is a fix for a change from OpenHistoricalMap/map-styles#32 that affected the name of the Historical (was Main) OHM map style in the map-styles repo
@danrademacher

Copy link
Copy Markdown

@erictheise I woke up this morning and realized I had not confirmed if you had separated out individual JSON files each style, as we discussed -- those are needed for external consumers (including the redirect we'll need from /main/main.json to /historical/historical.json

1ec5 added a commit to OpenHistoricalMap/openhistoricalmap-embed that referenced this pull request Mar 13, 2025
* Update staging URL for Historical Map Style

This is a fix for a change from OpenHistoricalMap/map-styles#32 that affected the name of the Historical (was Main) OHM map style in the map-styles repo

* Updated URLs to Railway, Japanese Scroll on staging

---------

Co-authored-by: Minh Nguyễn <[email protected]>
Rub21 pushed a commit to OpenHistoricalMap/openhistoricalmap-embed that referenced this pull request Mar 29, 2025
* Update staging URL for Historical Map Style

This is a fix for a change from OpenHistoricalMap/map-styles#32 that affected the name of the Historical (was Main) OHM map style in the map-styles repo

* Updated URLs to Railway, Japanese Scroll on staging

---------

Co-authored-by: Minh Nguyễn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants