@atlaspack/transformer-html 2.14.5-canary.145 → 2.14.5-canary.147
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/CHANGELOG.md +13 -0
- package/lib/inline.js +13 -1
- package/package.json +7 -6
- package/src/inline.ts +17 -2
- package/test/HTMLTransformer.test.ts +21 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# @atlaspack/transformer-html
|
2
2
|
|
3
|
+
## 2.15.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- [#731](https://github.com/atlassian-labs/atlaspack/pull/731) [`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2) Thanks [@marcins](https://github.com/marcins)! - Implement "inline isolated" scripts
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
|
12
|
+
- @atlaspack/feature-flags@2.21.0
|
13
|
+
- @atlaspack/rust@3.5.0
|
14
|
+
- @atlaspack/plugin@2.14.23
|
15
|
+
|
3
16
|
## 2.14.22
|
4
17
|
|
5
18
|
### Patch Changes
|
package/lib/inline.js
CHANGED
@@ -18,6 +18,13 @@ function _posthtml() {
|
|
18
18
|
};
|
19
19
|
return data;
|
20
20
|
}
|
21
|
+
function _featureFlags() {
|
22
|
+
const data = require("@atlaspack/feature-flags");
|
23
|
+
_featureFlags = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
21
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22
29
|
// @ts-expect-error TS2724
|
23
30
|
|
@@ -113,6 +120,11 @@ function extractInlineAssets(asset, ast) {
|
|
113
120
|
if ((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.type && node.tag === 'style') {
|
114
121
|
delete node.attrs.type;
|
115
122
|
}
|
123
|
+
let bundleBehavior = 'inline';
|
124
|
+
if ((0, _featureFlags().getFeatureFlag)('inlineIsolatedScripts') && typeof node.attrs['data-atlaspack-isolated'] !== 'undefined') {
|
125
|
+
bundleBehavior = 'inlineIsolated';
|
126
|
+
delete node.attrs['data-atlaspack-isolated'];
|
127
|
+
}
|
116
128
|
|
117
129
|
// insert parcelId to allow us to retrieve node during packaging
|
118
130
|
node.attrs['data-parcel-key'] = parcelKey;
|
@@ -126,7 +138,7 @@ function extractInlineAssets(asset, ast) {
|
|
126
138
|
type,
|
127
139
|
content: value,
|
128
140
|
uniqueKey: parcelKey,
|
129
|
-
bundleBehavior
|
141
|
+
bundleBehavior,
|
130
142
|
// @ts-expect-error TS2322
|
131
143
|
env,
|
132
144
|
meta: {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/transformer-html",
|
3
|
-
"version": "2.14.5-canary.
|
3
|
+
"version": "2.14.5-canary.147+6a4a9e878",
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -20,9 +20,10 @@
|
|
20
20
|
"node": ">= 16.0.0"
|
21
21
|
},
|
22
22
|
"dependencies": {
|
23
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
24
|
-
"@atlaspack/
|
25
|
-
"@atlaspack/
|
23
|
+
"@atlaspack/diagnostic": "2.14.1-canary.215+6a4a9e878",
|
24
|
+
"@atlaspack/feature-flags": "2.14.1-canary.215+6a4a9e878",
|
25
|
+
"@atlaspack/plugin": "2.14.5-canary.147+6a4a9e878",
|
26
|
+
"@atlaspack/rust": "3.2.1-canary.147+6a4a9e878",
|
26
27
|
"nullthrows": "^1.1.1",
|
27
28
|
"posthtml": "^0.16.5",
|
28
29
|
"posthtml-parser": "^0.10.1",
|
@@ -31,8 +32,8 @@
|
|
31
32
|
"srcset": "4"
|
32
33
|
},
|
33
34
|
"devDependencies": {
|
34
|
-
"@atlaspack/core": "2.16.2-canary.
|
35
|
+
"@atlaspack/core": "2.16.2-canary.147+6a4a9e878"
|
35
36
|
},
|
36
37
|
"type": "commonjs",
|
37
|
-
"gitHead": "
|
38
|
+
"gitHead": "6a4a9e878585987cdb3488f9655b645fc86935a5"
|
38
39
|
}
|
package/src/inline.ts
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
import type {
|
1
|
+
import type {
|
2
|
+
AST,
|
3
|
+
BundleBehavior,
|
4
|
+
MutableAsset,
|
5
|
+
TransformerResult,
|
6
|
+
} from '@atlaspack/types';
|
2
7
|
import {hashString} from '@atlaspack/rust';
|
3
8
|
// @ts-expect-error TS2724
|
4
9
|
import type {PostHTMLNode} from 'posthtml';
|
5
10
|
|
6
11
|
import PostHTML from 'posthtml';
|
12
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
7
13
|
|
8
14
|
const SCRIPT_TYPES = {
|
9
15
|
'application/javascript': 'js',
|
@@ -120,6 +126,15 @@ export default function extractInlineAssets(
|
|
120
126
|
delete node.attrs.type;
|
121
127
|
}
|
122
128
|
|
129
|
+
let bundleBehavior: BundleBehavior = 'inline';
|
130
|
+
if (
|
131
|
+
getFeatureFlag('inlineIsolatedScripts') &&
|
132
|
+
typeof node.attrs['data-atlaspack-isolated'] !== 'undefined'
|
133
|
+
) {
|
134
|
+
bundleBehavior = 'inlineIsolated';
|
135
|
+
delete node.attrs['data-atlaspack-isolated'];
|
136
|
+
}
|
137
|
+
|
123
138
|
// insert parcelId to allow us to retrieve node during packaging
|
124
139
|
node.attrs['data-parcel-key'] = parcelKey;
|
125
140
|
asset.setAST(ast); // mark dirty
|
@@ -133,7 +148,7 @@ export default function extractInlineAssets(
|
|
133
148
|
type,
|
134
149
|
content: value,
|
135
150
|
uniqueKey: parcelKey,
|
136
|
-
bundleBehavior
|
151
|
+
bundleBehavior,
|
137
152
|
// @ts-expect-error TS2322
|
138
153
|
env,
|
139
154
|
meta: {
|
@@ -351,4 +351,25 @@ describe('HTMLTransformer', () => {
|
|
351
351
|
},
|
352
352
|
]);
|
353
353
|
});
|
354
|
+
|
355
|
+
it('transforms simple inline script with data-atlaspack-isolated', async () => {
|
356
|
+
const code = `
|
357
|
+
<html>
|
358
|
+
<body>
|
359
|
+
<script data-atlaspack-isolated>console.log('blah'); require('path');</script>
|
360
|
+
</body>
|
361
|
+
</html>
|
362
|
+
`;
|
363
|
+
const {transformResult, inputAsset} = await runTestTransform(code);
|
364
|
+
assert(transformResult.includes(inputAsset));
|
365
|
+
const assets = normalizeAssets(transformResult);
|
366
|
+
assert.deepEqual(assets[1], {
|
367
|
+
type: 'js',
|
368
|
+
content: "console.log('blah'); require('path');",
|
369
|
+
uniqueKey: 'a8a37984d2e520b9',
|
370
|
+
bundleBehavior: 'inlineIsolated',
|
371
|
+
env: null,
|
372
|
+
meta: null,
|
373
|
+
});
|
374
|
+
});
|
354
375
|
});
|