elm-pages 3.0.21 → 3.0.23
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.
- package/README.md +1 -1
- package/generator/src/cli.js +6 -1
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/render.js +18 -4
- package/generator/template/elm.json +1 -1
- package/generator/template/package.json +1 -1
- package/package.json +1 -1
- package/src/Test/Html/Internal/ElmHtml/InternalTypes.elm +20 -3
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +20 -10
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
- [elm-pages Docs Site](https://elm-pages.com/docs)
|
|
13
13
|
- [elm-pages site showcase](https://elm-pages.com/showcase/)
|
|
14
|
-
- [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.2.
|
|
14
|
+
- [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.2.1/)
|
|
15
15
|
- [Quick start repo](https://github.com/dillonkearns/elm-pages-starter) [(live site hosted here)](https://elm-pages-starter.netlify.com)
|
|
16
16
|
- [Introducing `elm-pages` blog post](https://elm-pages.com/blog/introducing-elm-pages)
|
|
17
17
|
- [`examples` folder](https://github.com/dillonkearns/elm-pages/blob/master/examples/) (includes https://elm-pages.com site source) Use `git clone --recurse-submodules https://github.com/dillonkearns/elm-pages.git` so that there aren't missing files when you try to build the examples.
|
package/generator/src/cli.js
CHANGED
|
@@ -180,6 +180,10 @@ async function main() {
|
|
|
180
180
|
"Output path for compiled script",
|
|
181
181
|
"./myscript.mjs"
|
|
182
182
|
)
|
|
183
|
+
.option(
|
|
184
|
+
"--set-version <version>",
|
|
185
|
+
"Set the version string for the bundled script"
|
|
186
|
+
)
|
|
183
187
|
.option(
|
|
184
188
|
"--external <package-or-pattern>",
|
|
185
189
|
"build site to be served under a base path",
|
|
@@ -236,7 +240,8 @@ await renderer.runGenerator(
|
|
|
236
240
|
[...process.argv].splice(2),
|
|
237
241
|
customBackendTask,
|
|
238
242
|
Elm,
|
|
239
|
-
"${moduleName}"
|
|
243
|
+
"${moduleName}",
|
|
244
|
+
"${options.setVersion || "Version not set."}"
|
|
240
245
|
);
|
|
241
246
|
`;
|
|
242
247
|
// source: https://github.com/evanw/esbuild/pull/2067#issuecomment-1073039746
|
package/generator/src/render.js
CHANGED
|
@@ -77,12 +77,14 @@ export async function render(
|
|
|
77
77
|
* @param {string[]} cliOptions
|
|
78
78
|
* @param {any} portsFile
|
|
79
79
|
* @param {string} scriptModuleName
|
|
80
|
+
* @param {string} versionMessage
|
|
80
81
|
*/
|
|
81
82
|
export async function runGenerator(
|
|
82
83
|
cliOptions,
|
|
83
84
|
portsFile,
|
|
84
85
|
elmModule,
|
|
85
|
-
scriptModuleName
|
|
86
|
+
scriptModuleName,
|
|
87
|
+
versionMessage
|
|
86
88
|
) {
|
|
87
89
|
global.isRunningGenerator = true;
|
|
88
90
|
// const { fs, resetInMemoryFs } = require("./request-cache-fs.js")(true);
|
|
@@ -100,7 +102,8 @@ export async function runGenerator(
|
|
|
100
102
|
scriptModuleName,
|
|
101
103
|
"production",
|
|
102
104
|
"",
|
|
103
|
-
true
|
|
105
|
+
true,
|
|
106
|
+
versionMessage
|
|
104
107
|
);
|
|
105
108
|
return result;
|
|
106
109
|
} catch (error) {
|
|
@@ -119,6 +122,7 @@ export async function runGenerator(
|
|
|
119
122
|
* @param {typeof import("fs") | import("memfs").IFs} fs
|
|
120
123
|
* @param {boolean} hasFsAccess
|
|
121
124
|
* @param {string} scriptModuleName
|
|
125
|
+
* @param {string} versionMessage
|
|
122
126
|
*/
|
|
123
127
|
function runGeneratorAppHelp(
|
|
124
128
|
cliOptions,
|
|
@@ -128,12 +132,22 @@ function runGeneratorAppHelp(
|
|
|
128
132
|
scriptModuleName,
|
|
129
133
|
mode,
|
|
130
134
|
pagePath,
|
|
131
|
-
hasFsAccess
|
|
135
|
+
hasFsAccess,
|
|
136
|
+
versionMessage
|
|
132
137
|
) {
|
|
133
138
|
const isDevServer = mode !== "build";
|
|
134
139
|
let patternsToWatch = new Set();
|
|
135
140
|
let app = null;
|
|
136
141
|
let killApp;
|
|
142
|
+
// Handle version flag with early return
|
|
143
|
+
if (
|
|
144
|
+
cliOptions.length === 1 &&
|
|
145
|
+
(cliOptions[0] === "--version" || cliOptions[0] === "-v")
|
|
146
|
+
) {
|
|
147
|
+
console.log(versionMessage);
|
|
148
|
+
return Promise.resolve();
|
|
149
|
+
}
|
|
150
|
+
|
|
137
151
|
return new Promise((resolve, reject) => {
|
|
138
152
|
const isBytes = pagePath.match(/content\.dat\/?$/);
|
|
139
153
|
|
|
@@ -141,7 +155,7 @@ function runGeneratorAppHelp(
|
|
|
141
155
|
flags: {
|
|
142
156
|
compatibilityKey,
|
|
143
157
|
argv: ["", `elm-pages run ${scriptModuleName}`, ...cliOptions],
|
|
144
|
-
versionMessage
|
|
158
|
+
versionMessage,
|
|
145
159
|
},
|
|
146
160
|
});
|
|
147
161
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dillonkearns/elm-bcp47-language-tag": "2.0.0",
|
|
15
15
|
"dillonkearns/elm-form": "3.0.1",
|
|
16
16
|
"dillonkearns/elm-markdown": "7.0.1",
|
|
17
|
-
"dillonkearns/elm-pages": "10.2.
|
|
17
|
+
"dillonkearns/elm-pages": "10.2.1",
|
|
18
18
|
"elm/browser": "1.0.2",
|
|
19
19
|
"elm/bytes": "1.0.8",
|
|
20
20
|
"elm/core": "1.0.5",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ module Test.Html.Internal.ElmHtml.InternalTypes exposing
|
|
|
2
2
|
( ElmHtml(..), TextTagRecord, NodeRecord, CustomNodeRecord, MarkdownNodeRecord
|
|
3
3
|
, Facts, Tagger, EventHandler, ElementKind(..)
|
|
4
4
|
, Attribute(..), AttributeRecord, NamespacedAttributeRecord, PropertyRecord, EventRecord
|
|
5
|
-
, decodeElmHtml, emptyFacts, toElementKind, decodeAttribute
|
|
5
|
+
, decodeElmHtml, emptyFacts, toElementKind, decodeAttribute, isUnsafeName
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
{-| Internal types used to represent Elm Html in pure Elm
|
|
@@ -13,7 +13,7 @@ module Test.Html.Internal.ElmHtml.InternalTypes exposing
|
|
|
13
13
|
|
|
14
14
|
@docs Attribute, AttributeRecord, NamespacedAttributeRecord, PropertyRecord, EventRecord
|
|
15
15
|
|
|
16
|
-
@docs decodeElmHtml, emptyFacts, toElementKind, decodeAttribute
|
|
16
|
+
@docs decodeElmHtml, emptyFacts, toElementKind, decodeAttribute, isUnsafeName
|
|
17
17
|
|
|
18
18
|
-}
|
|
19
19
|
|
|
@@ -21,6 +21,7 @@ import Dict exposing (Dict)
|
|
|
21
21
|
import Html.Events
|
|
22
22
|
import Json.Decode exposing (field)
|
|
23
23
|
import Json.Encode
|
|
24
|
+
import Regex exposing (Regex)
|
|
24
25
|
import Test.Html.Internal.ElmHtml.Constants as Constants exposing (..)
|
|
25
26
|
import Test.Html.Internal.ElmHtml.Helpers exposing (..)
|
|
26
27
|
import Test.Html.Internal.ElmHtml.Markdown exposing (..)
|
|
@@ -124,6 +125,7 @@ type ElementKind
|
|
|
124
125
|
| EscapableRawTextElements
|
|
125
126
|
| ForeignElements
|
|
126
127
|
| NormalElements
|
|
128
|
+
| InvalidElements
|
|
127
129
|
|
|
128
130
|
|
|
129
131
|
type HtmlContext msg
|
|
@@ -510,12 +512,27 @@ escapableRawTextElements =
|
|
|
510
512
|
-}
|
|
511
513
|
|
|
512
514
|
|
|
515
|
+
unsafeName : Regex
|
|
516
|
+
unsafeName =
|
|
517
|
+
{- https://github.com/preactjs/preact-render-to-string/blob/27f340b6e7d77ec7775a49a78d105cad26fa0857/src/lib/util.js#L2 -}
|
|
518
|
+
Regex.fromString "[\\s\\n\\\\/='\"\\0<>]"
|
|
519
|
+
|> Maybe.withDefault Regex.never
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
isUnsafeName : String -> Bool
|
|
523
|
+
isUnsafeName name =
|
|
524
|
+
Regex.contains unsafeName name
|
|
525
|
+
|
|
526
|
+
|
|
513
527
|
{-| Identify the kind of element. Helper to convert an tag name into a type for
|
|
514
528
|
pattern matching.
|
|
515
529
|
-}
|
|
516
530
|
toElementKind : String -> ElementKind
|
|
517
531
|
toElementKind element =
|
|
518
|
-
if
|
|
532
|
+
if isUnsafeName element then
|
|
533
|
+
InvalidElements
|
|
534
|
+
|
|
535
|
+
else if List.member element voidElements then
|
|
519
536
|
VoidElements
|
|
520
537
|
|
|
521
538
|
else if List.member element rawTextElements then
|
|
@@ -115,23 +115,25 @@ nodeRecordToString options { tag, children, facts } =
|
|
|
115
115
|
styleValues
|
|
116
116
|
|> List.map (\( key, value ) -> key ++ ":" ++ value ++ ";")
|
|
117
117
|
|> String.join ""
|
|
118
|
-
|> (\styleString -> "style=\"" ++ styleString ++ "\"")
|
|
118
|
+
|> (\styleString -> "style=\"" ++ escapeHtml styleString ++ "\"")
|
|
119
119
|
|> Just
|
|
120
120
|
|
|
121
121
|
classes =
|
|
122
122
|
Dict.get "className" facts.stringAttributes
|
|
123
|
-
|> Maybe.map (\name -> "class=\"" ++ name ++ "\"")
|
|
123
|
+
|> Maybe.map (\name -> "class=\"" ++ escapeHtml name ++ "\"")
|
|
124
124
|
|
|
125
125
|
stringAttributes =
|
|
126
126
|
Dict.filter (\k v -> k /= "className") facts.stringAttributes
|
|
127
127
|
|> Dict.toList
|
|
128
|
+
|> List.filter (\( k, _ ) -> not (isUnsafeName k))
|
|
128
129
|
|> List.map (Tuple.mapFirst propertyToAttributeName)
|
|
129
|
-
|> List.map (\( k, v ) -> k ++ "=\"" ++ v ++ "\"")
|
|
130
|
+
|> List.map (\( k, v ) -> k ++ "=\"" ++ escapeHtml v ++ "\"")
|
|
130
131
|
|> String.join " "
|
|
131
132
|
|> Just
|
|
132
133
|
|
|
133
134
|
boolAttributes =
|
|
134
135
|
Dict.toList facts.boolAttributes
|
|
136
|
+
|> List.filter (\( k, _ ) -> not (isUnsafeName k))
|
|
135
137
|
|> List.filterMap
|
|
136
138
|
(\( k, v ) ->
|
|
137
139
|
if v then
|
|
@@ -144,6 +146,9 @@ nodeRecordToString options { tag, children, facts } =
|
|
|
144
146
|
|> Just
|
|
145
147
|
in
|
|
146
148
|
case toElementKind tag of
|
|
149
|
+
InvalidElements ->
|
|
150
|
+
[ "<!-- invalid element -->" ]
|
|
151
|
+
|
|
147
152
|
{- Void elements only have a start tag; end tags must not be
|
|
148
153
|
specified for void elements.
|
|
149
154
|
-}
|
|
@@ -187,10 +192,15 @@ escapeRawText kind rawText =
|
|
|
187
192
|
rawText
|
|
188
193
|
|
|
189
194
|
_ ->
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
escapeHtml rawText
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
escapeHtml : String -> String
|
|
199
|
+
escapeHtml rawText =
|
|
200
|
+
{- https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.server.js#L8-L26 -}
|
|
201
|
+
rawText
|
|
202
|
+
|> String.replace "&" "&"
|
|
203
|
+
|> String.replace "<" "<"
|
|
204
|
+
|> String.replace ">" ">"
|
|
205
|
+
|> String.replace "\"" """
|
|
206
|
+
|> String.replace "'" "'"
|