@parcel/transformer-pug 2.0.0-nightly.92 → 2.0.1

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.
@@ -5,51 +5,76 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _path = _interopRequireDefault(require("path"));
8
+ function _path() {
9
+ const data = _interopRequireDefault(require("path"));
9
10
 
10
- var _plugin = require("@parcel/plugin");
11
+ _path = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _plugin() {
19
+ const data = require("@parcel/plugin");
20
+
21
+ _plugin = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _pug() {
29
+ const data = _interopRequireDefault(require("pug"));
30
+
31
+ _pug = function () {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
11
37
 
12
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
39
 
14
- var _default = new _plugin.Transformer({
15
- async getConfig({
16
- asset
40
+ var _default = new (_plugin().Transformer)({
41
+ async loadConfig({
42
+ config
17
43
  }) {
18
- const config = await asset.getConfig(['.pugrc', '.pugrc.js', 'pug.config.js']);
19
- return config || {};
44
+ let configFile = await config.getConfig(['.pugrc', '.pugrc.js', 'pug.config.js']);
45
+
46
+ if (configFile) {
47
+ let isJavascript = _path().default.extname(configFile.filePath) === '.js';
48
+
49
+ if (isJavascript) {
50
+ config.invalidateOnStartup();
51
+ }
52
+
53
+ return configFile.contents;
54
+ }
20
55
  },
21
56
 
22
57
  async transform({
23
58
  asset,
24
- config,
25
- options
59
+ config
26
60
  }) {
27
- if (!config) {
28
- return [asset];
29
- }
30
-
31
- const pug = await options.packageManager.require('pug', asset.filePath);
61
+ const pugConfig = config !== null && config !== void 0 ? config : {};
32
62
  const content = await asset.getCode();
33
- const render = pug.compile(content, {
34
- degug: true,
63
+
64
+ const render = _pug().default.compile(content, {
35
65
  compileDebug: false,
36
- basedir: _path.default.dirname(asset.filePath),
66
+ basedir: _path().default.dirname(asset.filePath),
37
67
  filename: asset.filePath,
38
- pretty: config.pretty || false,
39
- doctype: config.doctype,
40
- filters: config.filters,
41
- filterOptions: config.filterOptions,
42
- filterAliases: config.filterAliases
68
+ ...pugConfig,
69
+ pretty: pugConfig.pretty || false
43
70
  });
44
71
 
45
72
  for (let filePath of render.dependencies) {
46
- await asset.addIncludedFile({
47
- filePath
48
- });
73
+ await asset.invalidateOnFileChange(filePath);
49
74
  }
50
75
 
51
76
  asset.type = 'html';
52
- asset.setCode(render(config.locals));
77
+ asset.setCode(render(pugConfig.locals));
53
78
  return [asset];
54
79
  }
55
80
 
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@parcel/transformer-pug",
3
- "version": "2.0.0-nightly.92+c0655c56",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/parcel"
11
+ },
8
12
  "repository": {
9
13
  "type": "git",
10
14
  "url": "https://github.com/parcel-bundler/parcel.git"
@@ -12,14 +16,12 @@
12
16
  "main": "lib/PugTransformer.js",
13
17
  "source": "src/PugTransformer.js",
14
18
  "engines": {
15
- "node": ">= 10.0.0",
16
- "parcel": "^2.0.0-alpha.1.1"
19
+ "node": ">= 12.0.0",
20
+ "parcel": "^2.0.1"
17
21
  },
18
22
  "dependencies": {
19
- "@parcel/plugin": "2.0.0-nightly.92+c0655c56"
20
- },
21
- "devDependencies": {
22
- "pug": "^2.0.4"
23
+ "@parcel/plugin": "^2.0.1",
24
+ "pug": "^3.0.2"
23
25
  },
24
- "gitHead": "c0655c56f7973492fdb28671029ddd923f17a244"
26
+ "gitHead": "28b47e6bdca7de2a06b7cc39a4a0b1df89f3fe15"
25
27
  }
@@ -2,43 +2,44 @@
2
2
 
3
3
  import path from 'path';
4
4
  import {Transformer} from '@parcel/plugin';
5
+ import pug from 'pug';
5
6
 
6
- export default new Transformer({
7
- async getConfig({asset}) {
8
- const config = await asset.getConfig([
7
+ export default (new Transformer({
8
+ async loadConfig({config}) {
9
+ let configFile = await config.getConfig([
9
10
  '.pugrc',
10
11
  '.pugrc.js',
11
12
  'pug.config.js',
12
13
  ]);
13
- return config || {};
14
- },
15
14
 
16
- async transform({asset, config, options}) {
17
- if (!config) {
18
- return [asset];
15
+ if (configFile) {
16
+ let isJavascript = path.extname(configFile.filePath) === '.js';
17
+ if (isJavascript) {
18
+ config.invalidateOnStartup();
19
+ }
20
+
21
+ return configFile.contents;
19
22
  }
23
+ },
20
24
 
21
- const pug = await options.packageManager.require('pug', asset.filePath);
25
+ async transform({asset, config}) {
26
+ const pugConfig = config ?? {};
22
27
  const content = await asset.getCode();
23
28
  const render = pug.compile(content, {
24
- degug: true,
25
29
  compileDebug: false,
26
30
  basedir: path.dirname(asset.filePath),
27
31
  filename: asset.filePath,
28
- pretty: config.pretty || false,
29
- doctype: config.doctype,
30
- filters: config.filters,
31
- filterOptions: config.filterOptions,
32
- filterAliases: config.filterAliases,
32
+ ...pugConfig,
33
+ pretty: pugConfig.pretty || false,
33
34
  });
34
35
 
35
36
  for (let filePath of render.dependencies) {
36
- await asset.addIncludedFile({filePath});
37
+ await asset.invalidateOnFileChange(filePath);
37
38
  }
38
39
 
39
40
  asset.type = 'html';
40
- asset.setCode(render(config.locals));
41
+ asset.setCode(render(pugConfig.locals));
41
42
 
42
43
  return [asset];
43
44
  },
44
- });
45
+ }): Transformer);