@lwrjs/nunjucks-view-provider 0.6.5 → 0.7.0-alpha.10

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/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2020, Salesforce.com, Inc.
4
+ All rights reserved.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -31,15 +31,13 @@ var import_fs = __toModule(require("fs"));
31
31
  var import_path = __toModule(require("path"));
32
32
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
33
33
  var import_nunjucks = __toModule(require("nunjucks"));
34
- var NunjucksCustomLoader = import_nunjucks.default.Loader.extend({
35
- init({contentDir, layoutsDir, rootDir, sourceDir}) {
36
- this.contentDir = contentDir;
37
- this.layoutsDir = layoutsDir;
38
- this.rootDir = rootDir;
39
- this.sourceDir = sourceDir;
40
- },
34
+ var NunjucksCustomLoader = class extends import_nunjucks.Loader {
35
+ constructor(config) {
36
+ super();
37
+ this.config = config;
38
+ }
41
39
  getSource(templatePath) {
42
- const {rootDir, layoutsDir, contentDir} = this;
40
+ const {rootDir, layoutsDir, contentDir, sourceDir} = this.config;
43
41
  templatePath = (0, import_shared_utils.normalizeResourcePath)(templatePath, {
44
42
  rootDir,
45
43
  layoutsDir,
@@ -48,7 +46,7 @@ var NunjucksCustomLoader = import_nunjucks.default.Loader.extend({
48
46
  });
49
47
  const isAbsolute = import_path.default.isAbsolute(templatePath);
50
48
  const isRelative = templatePath.startsWith("./");
51
- const fullTemplatePath = isAbsolute ? templatePath : isRelative ? import_path.default.join(this.sourceDir, templatePath) : import_path.default.join(rootDir, templatePath);
49
+ const fullTemplatePath = isAbsolute ? templatePath : isRelative ? import_path.default.join(sourceDir, templatePath) : import_path.default.join(rootDir, templatePath);
52
50
  if (!import_fs.default.existsSync(fullTemplatePath)) {
53
51
  throw new Error(`Unable to resolve nunjucks template. File not found on: "${fullTemplatePath}"`);
54
52
  }
@@ -60,7 +58,7 @@ var NunjucksCustomLoader = import_nunjucks.default.Loader.extend({
60
58
  noCache: true
61
59
  };
62
60
  }
63
- });
61
+ };
64
62
  function addHelperMethods(nunjucksEnv) {
65
63
  nunjucksEnv.addGlobal("startsWith", "function (s, sw) { return s.startsWith( sw )}");
66
64
  }
package/build/es/index.js CHANGED
@@ -55,7 +55,7 @@ export default class NunJucksViewProvider {
55
55
  const { content, data } = grayMatter(viewSource.originalSource);
56
56
  const { contentDir, layoutsDir, rootDir, watcher } = this;
57
57
  // In order to resolve relative paths for Nunjucks, we need to create a CustomLoader per View discovered
58
- // Altough we could reuse it, the perf is negligible and the code its cleaner this way
58
+ // Although we could reuse it, the perf is negligible and the code its cleaner this way
59
59
  const nunjucksCustomLoader = new NunjucksCustomLoader({ contentDir, layoutsDir, rootDir, sourceDir });
60
60
  if (watcher) {
61
61
  nunjucksCustomLoader.on('import', (importFile) => this.watchView(importFile, viewId));
@@ -1,4 +1,15 @@
1
- import { Environment } from 'nunjucks';
2
- export declare const NunjucksCustomLoader: any;
1
+ import { LoaderSource, Environment, Loader, ILoader } from 'nunjucks';
2
+ interface NunjucksLoaderConfig {
3
+ contentDir: string;
4
+ layoutsDir: string;
5
+ rootDir: string;
6
+ sourceDir: string;
7
+ }
8
+ export declare class NunjucksCustomLoader extends Loader implements ILoader {
9
+ config: NunjucksLoaderConfig;
10
+ constructor(config: NunjucksLoaderConfig);
11
+ getSource(templatePath: string): LoaderSource;
12
+ }
3
13
  export declare function addHelperMethods(nunjucksEnv: Environment): void;
14
+ export {};
4
15
  //# sourceMappingURL=nunjucks-env-utils.d.ts.map
@@ -1,18 +1,14 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { normalizeResourcePath } from '@lwrjs/shared-utils';
4
- import nunjucks from 'nunjucks';
5
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
- // @ts-ignore
7
- export const NunjucksCustomLoader = nunjucks.Loader.extend({
8
- init({ contentDir, layoutsDir, rootDir, sourceDir }) {
9
- this.contentDir = contentDir;
10
- this.layoutsDir = layoutsDir;
11
- this.rootDir = rootDir;
12
- this.sourceDir = sourceDir;
13
- },
4
+ import { Loader } from 'nunjucks';
5
+ export class NunjucksCustomLoader extends Loader {
6
+ constructor(config) {
7
+ super();
8
+ this.config = config;
9
+ }
14
10
  getSource(templatePath) {
15
- const { rootDir, layoutsDir, contentDir } = this;
11
+ const { rootDir, layoutsDir, contentDir, sourceDir } = this.config;
16
12
  templatePath = normalizeResourcePath(templatePath, {
17
13
  rootDir,
18
14
  layoutsDir,
@@ -24,7 +20,7 @@ export const NunjucksCustomLoader = nunjucks.Loader.extend({
24
20
  const fullTemplatePath = isAbsolute
25
21
  ? templatePath
26
22
  : isRelative
27
- ? path.join(this.sourceDir, templatePath)
23
+ ? path.join(sourceDir, templatePath)
28
24
  : path.join(rootDir, templatePath);
29
25
  if (!fs.existsSync(fullTemplatePath)) {
30
26
  throw new Error(`Unable to resolve nunjucks template. File not found on: "${fullTemplatePath}"`);
@@ -36,8 +32,8 @@ export const NunjucksCustomLoader = nunjucks.Loader.extend({
36
32
  path: fullTemplatePath,
37
33
  noCache: true,
38
34
  };
39
- },
40
- });
35
+ }
36
+ }
41
37
  export function addHelperMethods(nunjucksEnv) {
42
38
  nunjucksEnv.addGlobal('startsWith', 'function (s, sw) { return s.startsWith( sw )}');
43
39
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.5",
7
+ "version": "0.7.0-alpha.10",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,16 +30,17 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/base-template-engine": "0.6.5",
34
- "@lwrjs/shared-utils": "0.6.5",
33
+ "@lwrjs/base-template-engine": "0.7.0-alpha.10",
34
+ "@lwrjs/shared-utils": "0.7.0-alpha.10",
35
35
  "gray-matter": "^4.0.2",
36
36
  "nunjucks": "^3.2.2",
37
37
  "parse5-sax-parser": "^6.0.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.6.5"
40
+ "@lwrjs/types": "0.7.0-alpha.10"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=14.15.4 <17"
44
- }
44
+ },
45
+ "gitHead": "83c1e65e2169094cb55ac2c37e5aef16d3a9aa4a"
45
46
  }