Skip to content

Commit

Permalink
Use nodeResolve() in rollup to import node_modules by name
Browse files Browse the repository at this point in the history
Refactor / remove global L.symbol use to use
imported symbol of same name from "leaflet" import.

Update module specifiers to include ".js" where it is a file
in this project for consistency.

Update package.json to use specific forks of
proj4leaflet (module version), leaflet-locatecontrol (module version)

Get import of proj4leaflet from specific branch of maps4html/proj4leaflet
fork, which may never get merged upstream, but keeps differences in a
git repo, at least, instead of in the build script.

Update some tests to import the leaflet module directly

Create window.L.GridLayer, .L.DomUtil so that protomaps-leaflet will work.

Add rollup alias plugin to allow rollup to resove import of 'leaflet' to
correct file (Leaflet lacks a "module" key as of 1.9.4). This
allows us to not have to modify what's in node_modules.

Get import of proj4 from the module code that ships with that project.
The maps4html/proj4leaflet fork works with proj4 code as shipped.

Update "module","main" keys with correct path
relative to dist/ subdirectory

Use npm-installed esm version of leaflet-locatecontrol
  • Loading branch information
prushforth committed Oct 30, 2024
1 parent 56a8791 commit 3774952
Show file tree
Hide file tree
Showing 61 changed files with 1,453 additions and 1,517 deletions.
86 changes: 29 additions & 57 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module.exports = function(grunt) {
const Diff = require('diff');
const nodeResolve = require('@rollup/plugin-node-resolve');
const loadLocalePlugin = require('./load-locales.js');
grunt.initConfig({
const Diff = require('diff');
const nodeResolve = require('@rollup/plugin-node-resolve');
const loadLocalePlugin = require('./load-locales.js');
const alias = require('@rollup/plugin-alias');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cssmin: {
options: {
Expand Down Expand Up @@ -50,30 +51,6 @@ grunt.initConfig({
copy : {
main : {
files: [
{
expand: true,
cwd: 'node_modules/leaflet/dist/',
flatten: true,
filter: 'isFile',
src: ['leaflet-src.js'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/proj4/dist/',
flatten: true,
filter: 'isFile',
src: ['proj4-src.js'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/proj4leaflet/src/',
flatten: true,
filter: 'isFile',
src: ['proj4leaflet.js'],
dest: 'dist/'
},
{
expand: true,
flatten: true,
Expand All @@ -87,28 +64,12 @@ grunt.initConfig({
filter: 'isFile',
src: ['src/pmtilesRules.js'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/leaflet.locatecontrol/src/',
flatten: true,
filter: 'isFile',
src: ['L.Control.Locate.js'],
dest: 'dist/'
}
],
options: {
process: function (content, srcpath) {
// see patch.diff file for comments on why patching is necessary
if (srcpath.includes('proj4leaflet.js')) {
console.log('PATCHING: ', srcpath);
const patch = grunt.file.read('src/proj4leaflet/patch.diff');
return Diff.applyPatch(content, patch);
} else if (srcpath.includes('proj4-src.js')) {
console.log('PATCHING: ', srcpath);
const patch = grunt.file.read('src/proj4/patch.diff');
return Diff.applyPatch(content, patch);
} else if (srcpath.includes('index.html')) {
if (srcpath.includes('index.html')) {
console.log('MODIFYING: ', srcpath);
var pathToModuleRE = /dist\/mapml\.js/gi;
return content.replace(pathToModuleRE,"./mapml.js");
Expand Down Expand Up @@ -173,7 +134,7 @@ grunt.initConfig({
},
clean: {
dist: ['dist'],
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js','dist/mapmlviewer.js'],
tidyup: ['dist/mapmlviewer.js'],
experiments: {
options: {force: true},
src: ['../experiments/dist']
Expand All @@ -192,17 +153,28 @@ grunt.initConfig({
}
},
rollup: {
options: {
format: 'es',
plugins: [nodeResolve(),loadLocalePlugin()],
external: './pmtilesRules.js'
},
main: {
dest: 'dist/mapmlviewer.js',
src: 'src/mapml/index.js' // Only one source file is permitted
}
},
prettier: {
options: {
format: 'es',
plugins: [
nodeResolve(),
loadLocalePlugin(),
alias({
entries: [
{
find: 'leaflet',
replacement: 'leaflet/dist/leaflet-src.esm.js'
}
]
})
],
external: './pmtilesRules.js'
},
main: {
dest: 'dist/mapmlviewer.js',
src: 'src/mapml/index.js' // Only one source file is permitted
}
},
prettier: {
options: {
// https://prettier.io/docs/en/options.html
progress: true
Expand Down
Loading

0 comments on commit 3774952

Please sign in to comment.