@lwrjs/lwc-module-provider 0.4.5 → 0.5.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.
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.
@@ -45,8 +45,17 @@ function setupModuleCache(cacheDir) {
45
45
  import_fs.default.writeFileSync(lwcCacheIndexPath, "[]");
46
46
  return {lwcCacheDir, lwcCacheIndex: new Map()};
47
47
  } else {
48
- const cacheIndexJson = JSON.parse(import_fs.default.readFileSync(lwcCacheIndexPath, "utf-8"));
49
- return {lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson)};
48
+ const rawIndex = import_fs.default.readFileSync(lwcCacheIndexPath, "utf-8");
49
+ try {
50
+ const cacheIndexJson = JSON.parse(rawIndex);
51
+ return {lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson)};
52
+ } catch (err) {
53
+ const newErr = new Error("Invalid LWC Index: " + rawIndex);
54
+ if (err.stack) {
55
+ newErr.stack += "\nCaused by: " + err.stack;
56
+ }
57
+ throw newErr;
58
+ }
50
59
  }
51
60
  }
52
61
  function addCompiledModuleCacheEntry(moduleSource, compilerResult, {lwcCacheIndex, lwcCacheDir}) {
@@ -135,7 +135,8 @@ var LwcModuleProvider = class {
135
135
  return this.moduleEntryVersionCache.get(cacheKey2);
136
136
  }
137
137
  }
138
- const [baseSpecifier, fileRelativePath] = specifier.split("#");
138
+ const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
139
+ const fileRelativePath = fileRelativePathRaw?.split("?")[0];
139
140
  let moduleEntry;
140
141
  if (fileRelativePath && version) {
141
142
  const cacheKey2 = getModuleEntryCacheKey(specifier, version);
@@ -43,11 +43,15 @@ function resolveModuleSpecifier(specifier, importer, modules = []) {
43
43
  return {...resolvedModule, version};
44
44
  }
45
45
  function isImplicitLwcImport(entry, specifier) {
46
- const [, fileRelativePath] = specifier.split("#");
46
+ const [, fileRelativePathQs] = specifier.split("#");
47
+ const fileRelativePath = fileRelativePathQs?.split("?")[0];
47
48
  if (!fileRelativePath || import_fs.default.existsSync(entry)) {
48
49
  return false;
49
50
  }
50
51
  const ext = import_path.default.extname(fileRelativePath);
52
+ if (fileRelativePath.endsWith(".scoped.css")) {
53
+ return true;
54
+ }
51
55
  if (ext !== ".html" && ext !== ".css") {
52
56
  return false;
53
57
  }
package/build/es/cache.js CHANGED
@@ -18,8 +18,18 @@ export function setupModuleCache(cacheDir) {
18
18
  return { lwcCacheDir, lwcCacheIndex: new Map() };
19
19
  }
20
20
  else {
21
- const cacheIndexJson = JSON.parse(fs.readFileSync(lwcCacheIndexPath, 'utf-8'));
22
- return { lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson) };
21
+ const rawIndex = fs.readFileSync(lwcCacheIndexPath, 'utf-8');
22
+ try {
23
+ const cacheIndexJson = JSON.parse(rawIndex);
24
+ return { lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson) };
25
+ }
26
+ catch (err) {
27
+ const newErr = new Error('Invalid LWC Index: ' + rawIndex);
28
+ if (err.stack) {
29
+ newErr.stack += '\nCaused by: ' + err.stack;
30
+ }
31
+ throw newErr;
32
+ }
23
33
  }
24
34
  }
25
35
  export function addCompiledModuleCacheEntry(moduleSource, compilerResult, { lwcCacheIndex, lwcCacheDir }) {
package/build/es/index.js CHANGED
@@ -105,7 +105,8 @@ export default class LwcModuleProvider {
105
105
  // Strip any filenames out of the specifier
106
106
  // eg: 'c/myApp#myApp.css' => 'c/myApp' and 'myApp.css'
107
107
  // eg: 'some/where#lib/util' => 'some/where' and 'lib/util'
108
- const [baseSpecifier, fileRelativePath] = specifier.split('#');
108
+ const [baseSpecifier, fileRelativePathRaw] = specifier.split('#');
109
+ const fileRelativePath = fileRelativePathRaw?.split('?')[0]; // Remove queryString as LWC uses it for scope style
109
110
  let moduleEntry;
110
111
  // If this is a relative import, check the cache for the base specifier first
111
112
  if (fileRelativePath && version) {
package/build/es/utils.js CHANGED
@@ -13,13 +13,18 @@ export function resolveModuleSpecifier(specifier, importer, modules = []) {
13
13
  // An implicit import is dependency that the LWC includes automatically to "auto-magically" bind JS, HTML and CSS
14
14
  // Sometimes this file might not exist, in which case we need to provide a default
15
15
  export function isImplicitLwcImport(entry, specifier) {
16
- const [, fileRelativePath] = specifier.split('#');
16
+ const [, fileRelativePathQs] = specifier.split('#');
17
+ const fileRelativePath = fileRelativePathQs?.split('?')[0]; // Remove queryString as LWC uses it for scope style
17
18
  // If is not relative or the file exists it's not an implicit import
18
19
  if (!fileRelativePath || fs.existsSync(entry)) {
19
20
  return false;
20
21
  }
21
22
  // The LWC compiler only does implicit imports for html or css
22
23
  const ext = path.extname(fileRelativePath);
24
+ // Implicit scope style
25
+ if (fileRelativePath.endsWith('.scoped.css')) {
26
+ return true;
27
+ }
23
28
  if (ext !== '.html' && ext !== '.css') {
24
29
  return false;
25
30
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.4.5",
7
+ "version": "0.5.1",
8
8
  "homepage": "https://lwr.dev/",
9
9
  "repository": {
10
10
  "type": "git",
@@ -32,13 +32,14 @@
32
32
  "dependencies": {
33
33
  "@babel/preset-typescript": "^7.9.0",
34
34
  "@lwc/module-resolver": "2.3.1",
35
- "@lwrjs/shared-utils": "0.4.5",
35
+ "@lwrjs/shared-utils": "0.5.1",
36
36
  "es-module-lexer": "^0.3.18"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.4.5"
39
+ "@lwrjs/types": "0.5.1"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=14.15.4 <15"
43
- }
43
+ },
44
+ "gitHead": "007da758483711eb4f3422c3c94f7a816d20c71d"
44
45
  }