@atlaspack/transformer-html 2.14.5-canary.145 → 2.14.5-canary.146

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/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: 'inline',
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.145+231e0acb3",
3
+ "version": "2.14.5-canary.146+23d561e51",
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.213+231e0acb3",
24
- "@atlaspack/plugin": "2.14.5-canary.145+231e0acb3",
25
- "@atlaspack/rust": "3.2.1-canary.145+231e0acb3",
23
+ "@atlaspack/diagnostic": "2.14.1-canary.214+23d561e51",
24
+ "@atlaspack/feature-flags": "2.14.1-canary.214+23d561e51",
25
+ "@atlaspack/plugin": "2.14.5-canary.146+23d561e51",
26
+ "@atlaspack/rust": "3.2.1-canary.146+23d561e51",
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.145+231e0acb3"
35
+ "@atlaspack/core": "2.16.2-canary.146+23d561e51"
35
36
  },
36
37
  "type": "commonjs",
37
- "gitHead": "231e0acb3008231b09b224868f415771d087c23c"
38
+ "gitHead": "23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2"
38
39
  }
package/src/inline.ts CHANGED
@@ -1,9 +1,15 @@
1
- import type {AST, MutableAsset, TransformerResult} from '@atlaspack/types';
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: 'inline',
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
  });