@navita/next-plugin 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,101 +3,7 @@
3
3
  var webpackPlugin = require('@navita/webpack-plugin');
4
4
  var NextMiniCssExtractPlugin = require('next/dist/build/webpack/plugins/mini-css-extract-plugin');
5
5
  var findPagesDir = require('next/dist/lib/find-pages-dir');
6
-
7
- const merge = (...merge)=>{
8
- const result = {};
9
- for (const usedIds of merge){
10
- for(const key in usedIds){
11
- result[key] = [
12
- ...result[key] || [],
13
- ...usedIds[key] || []
14
- ];
15
- }
16
- }
17
- for(const key1 in result){
18
- result[key1] = [
19
- ...new Set(result[key1])
20
- ];
21
- }
22
- return result;
23
- };
24
- const intersect = (...intersect)=>{
25
- const result = {};
26
- for (const usedIds of intersect){
27
- for(const key in usedIds){
28
- result[key] = result[key] ? result[key].filter((id)=>usedIds[key].includes(id)) : usedIds[key];
29
- }
30
- }
31
- return result;
32
- };
33
- // structuredClone would be better, but since Next.js version 13 is at node 16.14.0,
34
- // we can't use it.
35
- const copy = (source)=>JSON.parse(JSON.stringify(source));
36
- const removeParentFromCurrent = (usedIds, parentUsedIds)=>{
37
- for(const key in parentUsedIds){
38
- if (usedIds[key] && parentUsedIds[key]) {
39
- usedIds[key] = usedIds[key].filter((id)=>!parentUsedIds[key].includes(id));
40
- }
41
- }
42
- };
43
- function optimizeCSSOutput(output) {
44
- const nameToChunk = Object.fromEntries(Array.from(output.keys()).filter((x)=>x.name).map((x)=>[
45
- x.name,
46
- x
47
- ]));
48
- const getAllParentUsedIds = (chunk)=>{
49
- const { name: route } = chunk;
50
- if (!route) {
51
- // If we don't have a name, it's a dynamic chunk.
52
- const value = output.get(chunk);
53
- if (value.parents.length === 0) {
54
- return [];
55
- }
56
- return [
57
- intersect(...value.parents.map((parent)=>merge(...getAllParentUsedIds(parent), output.get(parent).usedIds)))
58
- ];
59
- }
60
- if (route.startsWith('pages/')) {
61
- const routes = [
62
- 'pages/_document',
63
- 'pages/_app',
64
- route
65
- ];
66
- const currentRouteIndex = routes.indexOf(route);
67
- return routes.filter((_, index)=>currentRouteIndex > index).map((x)=>output.get(nameToChunk[x])).filter(Boolean).map((x)=>copy(x.usedIds));
68
- }
69
- const parts = route.split('/');
70
- const parents = [];
71
- let currentPart = '';
72
- for (const part of parts){
73
- currentPart = [
74
- currentPart,
75
- part
76
- ].filter(Boolean).join('/');
77
- const possibleParent = `${currentPart}/layout`;
78
- if (route === possibleParent) {
79
- continue;
80
- }
81
- const parentChunk = nameToChunk[possibleParent];
82
- if (output.has(parentChunk)) {
83
- parents.push(copy(output.get(parentChunk).usedIds));
84
- }
85
- }
86
- return parents;
87
- };
88
- const newOutput = new Map();
89
- for (const chunk of output.keys()){
90
- const currentUsedIds = copy(output.get(chunk).usedIds);
91
- for (const parent of getAllParentUsedIds(chunk)){
92
- removeParentFromCurrent(currentUsedIds, parent);
93
- }
94
- newOutput.set(chunk, {
95
- ...output.get(chunk),
96
- usedIds: currentUsedIds
97
- });
98
- }
99
- return newOutput;
100
- }
6
+ var optimizeCSSOutput = require('./optimizeCSSOutput.cjs');
101
7
 
102
8
  const MiniCssExtractPlugin = NextMiniCssExtractPlugin['default'];
103
9
  const createNavitaStylePlugin = (navitaConfig = {})=>(nextConfig)=>Object.assign({}, nextConfig, {
@@ -162,7 +68,7 @@ const createNavitaStylePlugin = (navitaConfig = {})=>(nextConfig)=>Object.assign
162
68
  config.plugins?.push(new webpackPlugin.NavitaPlugin({
163
69
  outputCss,
164
70
  ...navitaConfig,
165
- optimizeCSSOutput
71
+ optimizeCSSOutput: optimizeCSSOutput.optimizeCSSOutput
166
72
  }));
167
73
  if (typeof nextConfig.webpack === "function") {
168
74
  return nextConfig.webpack(config, options);
package/index.mjs CHANGED
@@ -3,101 +3,7 @@ const require = createRequire$1(import.meta.url);
3
3
  import { getNavitaModule, NAVITA_MODULE_TYPE, NavitaPlugin } from '@navita/webpack-plugin';
4
4
  import NextMiniCssExtractPlugin from 'next/dist/build/webpack/plugins/mini-css-extract-plugin';
5
5
  import { findPagesDir } from 'next/dist/lib/find-pages-dir';
6
-
7
- const merge = (...merge)=>{
8
- const result = {};
9
- for (const usedIds of merge){
10
- for(const key in usedIds){
11
- result[key] = [
12
- ...result[key] || [],
13
- ...usedIds[key] || []
14
- ];
15
- }
16
- }
17
- for(const key1 in result){
18
- result[key1] = [
19
- ...new Set(result[key1])
20
- ];
21
- }
22
- return result;
23
- };
24
- const intersect = (...intersect)=>{
25
- const result = {};
26
- for (const usedIds of intersect){
27
- for(const key in usedIds){
28
- result[key] = result[key] ? result[key].filter((id)=>usedIds[key].includes(id)) : usedIds[key];
29
- }
30
- }
31
- return result;
32
- };
33
- // structuredClone would be better, but since Next.js version 13 is at node 16.14.0,
34
- // we can't use it.
35
- const copy = (source)=>JSON.parse(JSON.stringify(source));
36
- const removeParentFromCurrent = (usedIds, parentUsedIds)=>{
37
- for(const key in parentUsedIds){
38
- if (usedIds[key] && parentUsedIds[key]) {
39
- usedIds[key] = usedIds[key].filter((id)=>!parentUsedIds[key].includes(id));
40
- }
41
- }
42
- };
43
- function optimizeCSSOutput(output) {
44
- const nameToChunk = Object.fromEntries(Array.from(output.keys()).filter((x)=>x.name).map((x)=>[
45
- x.name,
46
- x
47
- ]));
48
- const getAllParentUsedIds = (chunk)=>{
49
- const { name: route } = chunk;
50
- if (!route) {
51
- // If we don't have a name, it's a dynamic chunk.
52
- const value = output.get(chunk);
53
- if (value.parents.length === 0) {
54
- return [];
55
- }
56
- return [
57
- intersect(...value.parents.map((parent)=>merge(...getAllParentUsedIds(parent), output.get(parent).usedIds)))
58
- ];
59
- }
60
- if (route.startsWith('pages/')) {
61
- const routes = [
62
- 'pages/_document',
63
- 'pages/_app',
64
- route
65
- ];
66
- const currentRouteIndex = routes.indexOf(route);
67
- return routes.filter((_, index)=>currentRouteIndex > index).map((x)=>output.get(nameToChunk[x])).filter(Boolean).map((x)=>copy(x.usedIds));
68
- }
69
- const parts = route.split('/');
70
- const parents = [];
71
- let currentPart = '';
72
- for (const part of parts){
73
- currentPart = [
74
- currentPart,
75
- part
76
- ].filter(Boolean).join('/');
77
- const possibleParent = `${currentPart}/layout`;
78
- if (route === possibleParent) {
79
- continue;
80
- }
81
- const parentChunk = nameToChunk[possibleParent];
82
- if (output.has(parentChunk)) {
83
- parents.push(copy(output.get(parentChunk).usedIds));
84
- }
85
- }
86
- return parents;
87
- };
88
- const newOutput = new Map();
89
- for (const chunk of output.keys()){
90
- const currentUsedIds = copy(output.get(chunk).usedIds);
91
- for (const parent of getAllParentUsedIds(chunk)){
92
- removeParentFromCurrent(currentUsedIds, parent);
93
- }
94
- newOutput.set(chunk, {
95
- ...output.get(chunk),
96
- usedIds: currentUsedIds
97
- });
98
- }
99
- return newOutput;
100
- }
6
+ import { optimizeCSSOutput } from './optimizeCSSOutput.mjs';
101
7
 
102
8
  const MiniCssExtractPlugin = NextMiniCssExtractPlugin['default'];
103
9
  const createNavitaStylePlugin = (navitaConfig = {})=>(nextConfig)=>Object.assign({}, nextConfig, {
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ const merge = (...merge)=>{
4
+ const result = {};
5
+ for (const usedIds of merge){
6
+ for(const key in usedIds){
7
+ result[key] = [
8
+ ...result[key] || [],
9
+ ...usedIds[key] || []
10
+ ];
11
+ }
12
+ }
13
+ for(const key1 in result){
14
+ result[key1] = [
15
+ ...new Set(result[key1])
16
+ ];
17
+ }
18
+ return result;
19
+ };
20
+ const intersect = (...intersect)=>{
21
+ const result = {};
22
+ for (const usedIds of intersect){
23
+ for(const key in usedIds){
24
+ result[key] = result[key] ? result[key].filter((id)=>usedIds[key].includes(id)) : usedIds[key];
25
+ }
26
+ }
27
+ return result;
28
+ };
29
+ // structuredClone would be better, but since Next.js version 13 is at node 16.14.0,
30
+ // we can't use it.
31
+ const copy = (source)=>JSON.parse(JSON.stringify(source));
32
+ const removeParentFromCurrent = (usedIds, parentUsedIds)=>{
33
+ for(const key in parentUsedIds){
34
+ if (usedIds[key] && parentUsedIds[key]) {
35
+ usedIds[key] = usedIds[key].filter((id)=>!parentUsedIds[key].includes(id));
36
+ }
37
+ }
38
+ };
39
+ function optimizeCSSOutput(output) {
40
+ const nameToChunk = Object.fromEntries(Array.from(output.keys()).filter((x)=>x.name).map((x)=>[
41
+ x.name,
42
+ x
43
+ ]));
44
+ const getAllParentUsedIds = (chunk)=>{
45
+ const { name: route } = chunk;
46
+ if (!route) {
47
+ // If we don't have a name, it's a dynamic chunk.
48
+ const value = output.get(chunk);
49
+ if (value.parents.length === 0) {
50
+ return [];
51
+ }
52
+ return [
53
+ intersect(...value.parents.map((parent)=>merge(...getAllParentUsedIds(parent), output.get(parent).usedIds)))
54
+ ];
55
+ }
56
+ if (route.startsWith('pages/')) {
57
+ const routes = [
58
+ 'pages/_document',
59
+ 'pages/_app',
60
+ route
61
+ ];
62
+ const currentRouteIndex = routes.indexOf(route);
63
+ return routes.filter((_, index)=>currentRouteIndex > index).map((x)=>output.get(nameToChunk[x])).filter(Boolean).map((x)=>copy(x.usedIds));
64
+ }
65
+ const parts = route.split('/');
66
+ const parents = [];
67
+ let currentPart = '';
68
+ for (const part of parts){
69
+ currentPart = [
70
+ currentPart,
71
+ part
72
+ ].filter(Boolean).join('/');
73
+ const possibleParent = `${currentPart}/layout`;
74
+ if (route === possibleParent) {
75
+ continue;
76
+ }
77
+ const parentChunk = nameToChunk[possibleParent];
78
+ if (output.has(parentChunk)) {
79
+ parents.push(copy(output.get(parentChunk).usedIds));
80
+ }
81
+ }
82
+ return parents;
83
+ };
84
+ const newOutput = new Map();
85
+ for (const chunk of output.keys()){
86
+ const currentUsedIds = copy(output.get(chunk).usedIds);
87
+ for (const parent of getAllParentUsedIds(chunk)){
88
+ removeParentFromCurrent(currentUsedIds, parent);
89
+ }
90
+ newOutput.set(chunk, {
91
+ ...output.get(chunk),
92
+ usedIds: currentUsedIds
93
+ });
94
+ }
95
+ return newOutput;
96
+ }
97
+
98
+ exports.optimizeCSSOutput = optimizeCSSOutput;
@@ -0,0 +1,96 @@
1
+ const merge = (...merge)=>{
2
+ const result = {};
3
+ for (const usedIds of merge){
4
+ for(const key in usedIds){
5
+ result[key] = [
6
+ ...result[key] || [],
7
+ ...usedIds[key] || []
8
+ ];
9
+ }
10
+ }
11
+ for(const key1 in result){
12
+ result[key1] = [
13
+ ...new Set(result[key1])
14
+ ];
15
+ }
16
+ return result;
17
+ };
18
+ const intersect = (...intersect)=>{
19
+ const result = {};
20
+ for (const usedIds of intersect){
21
+ for(const key in usedIds){
22
+ result[key] = result[key] ? result[key].filter((id)=>usedIds[key].includes(id)) : usedIds[key];
23
+ }
24
+ }
25
+ return result;
26
+ };
27
+ // structuredClone would be better, but since Next.js version 13 is at node 16.14.0,
28
+ // we can't use it.
29
+ const copy = (source)=>JSON.parse(JSON.stringify(source));
30
+ const removeParentFromCurrent = (usedIds, parentUsedIds)=>{
31
+ for(const key in parentUsedIds){
32
+ if (usedIds[key] && parentUsedIds[key]) {
33
+ usedIds[key] = usedIds[key].filter((id)=>!parentUsedIds[key].includes(id));
34
+ }
35
+ }
36
+ };
37
+ function optimizeCSSOutput(output) {
38
+ const nameToChunk = Object.fromEntries(Array.from(output.keys()).filter((x)=>x.name).map((x)=>[
39
+ x.name,
40
+ x
41
+ ]));
42
+ const getAllParentUsedIds = (chunk)=>{
43
+ const { name: route } = chunk;
44
+ if (!route) {
45
+ // If we don't have a name, it's a dynamic chunk.
46
+ const value = output.get(chunk);
47
+ if (value.parents.length === 0) {
48
+ return [];
49
+ }
50
+ return [
51
+ intersect(...value.parents.map((parent)=>merge(...getAllParentUsedIds(parent), output.get(parent).usedIds)))
52
+ ];
53
+ }
54
+ if (route.startsWith('pages/')) {
55
+ const routes = [
56
+ 'pages/_document',
57
+ 'pages/_app',
58
+ route
59
+ ];
60
+ const currentRouteIndex = routes.indexOf(route);
61
+ return routes.filter((_, index)=>currentRouteIndex > index).map((x)=>output.get(nameToChunk[x])).filter(Boolean).map((x)=>copy(x.usedIds));
62
+ }
63
+ const parts = route.split('/');
64
+ const parents = [];
65
+ let currentPart = '';
66
+ for (const part of parts){
67
+ currentPart = [
68
+ currentPart,
69
+ part
70
+ ].filter(Boolean).join('/');
71
+ const possibleParent = `${currentPart}/layout`;
72
+ if (route === possibleParent) {
73
+ continue;
74
+ }
75
+ const parentChunk = nameToChunk[possibleParent];
76
+ if (output.has(parentChunk)) {
77
+ parents.push(copy(output.get(parentChunk).usedIds));
78
+ }
79
+ }
80
+ return parents;
81
+ };
82
+ const newOutput = new Map();
83
+ for (const chunk of output.keys()){
84
+ const currentUsedIds = copy(output.get(chunk).usedIds);
85
+ for (const parent of getAllParentUsedIds(chunk)){
86
+ removeParentFromCurrent(currentUsedIds, parent);
87
+ }
88
+ newOutput.set(chunk, {
89
+ ...output.get(chunk),
90
+ usedIds: currentUsedIds
91
+ });
92
+ }
93
+ return newOutput;
94
+ }
95
+
96
+ export { optimizeCSSOutput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/next-plugin",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Next.js integration for Navita",
5
5
  "keywords": [
6
6
  "next",
@@ -14,18 +14,18 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": "./index.mjs",
17
- "require": "./index.js",
17
+ "require": "./index.cjs",
18
18
  "types": "./index.d.ts"
19
19
  },
20
20
  "./fromServerLoader": {
21
21
  "import": "./fromServerLoader.mjs",
22
- "require": "./fromServerLoader.js",
22
+ "require": "./fromServerLoader.cjs",
23
23
  "types": "./fromServerLoader.d.ts"
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
27
  "browserslist": "^4.21.5",
28
- "@navita/webpack-plugin": "0.0.10"
28
+ "@navita/webpack-plugin": "0.0.11"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "next": ">=12 || >=13",
File without changes