@parcel/transformer-stylus 2.0.0-beta.2 → 2.0.0-nightly.1004

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.
@@ -121,7 +121,7 @@ var _default = new (_plugin().Transformer)({
121
121
  let isJavascript = _path().default.extname(configFile.filePath) === '.js';
122
122
 
123
123
  if (isJavascript) {
124
- config.shouldInvalidateOnStartup();
124
+ config.invalidateOnStartup();
125
125
  } // Resolve relative paths from config file
126
126
 
127
127
 
@@ -129,7 +129,7 @@ var _default = new (_plugin().Transformer)({
129
129
  configFile.contents.paths = configFile.contents.paths.map(p => _path().default.resolve(_path().default.dirname(configFile.filePath), p));
130
130
  }
131
131
 
132
- config.setResult(configFile.contents);
132
+ return configFile.contents;
133
133
  }
134
134
  },
135
135
 
@@ -170,32 +170,43 @@ var _default = new (_plugin().Transformer)({
170
170
 
171
171
  exports.default = _default;
172
172
 
173
- async function getDependencies(code, filepath, asset, resolve, options, parcelOptions, nativeGlob, seen = new Set()) {
173
+ function attemptResolve(importedPath, filepath, asset, resolve, deps) {
174
+ if (deps.has(importedPath)) {
175
+ return;
176
+ }
177
+
178
+ if ((0, _utils().isGlob)(importedPath)) {
179
+ // Invalidate when new files are created that match the glob pattern.
180
+ let absoluteGlob = _path().default.resolve(_path().default.dirname(filepath), importedPath);
181
+
182
+ asset.invalidateOnFileCreate({
183
+ glob: absoluteGlob
184
+ });
185
+ deps.set(importedPath, (0, _utils().glob)(absoluteGlob, asset.fs, {
186
+ onlyFiles: true
187
+ }).then(entries => Promise.all(entries.map(entry => resolve(filepath, './' + _path().default.relative(_path().default.dirname(filepath), entry))))));
188
+ } else {
189
+ deps.set(importedPath, resolve(filepath, importedPath));
190
+ }
191
+ }
192
+
193
+ async function getDependencies(code, filepath, asset, resolve, options, parcelOptions, nativeGlob, seen = new Set(), includeImports = true) {
174
194
  seen.add(filepath);
175
195
  _nodes().default.filename = asset.filePath;
176
196
  let parser = new (_parser().default)(code, options);
177
197
  let ast = parser.parse();
178
198
  let deps = new Map();
179
199
 
200
+ if (includeImports && options.imports) {
201
+ for (let importedPath of options.imports) {
202
+ attemptResolve(importedPath, filepath, asset, resolve, deps);
203
+ }
204
+ }
205
+
180
206
  class ImportVisitor extends _depsResolver().default {
181
207
  visitImport(imported) {
182
208
  let importedPath = imported.path.first.string;
183
-
184
- if (!deps.has(importedPath)) {
185
- if ((0, _utils().isGlob)(importedPath)) {
186
- // Invalidate when new files are created that match the glob pattern.
187
- let absoluteGlob = _path().default.resolve(_path().default.dirname(filepath), importedPath);
188
-
189
- asset.invalidateOnFileCreate({
190
- glob: absoluteGlob
191
- });
192
- deps.set(importedPath, (0, _utils().glob)(absoluteGlob, asset.fs, {
193
- onlyFiles: true
194
- }).then(entries => Promise.all(entries.map(entry => resolve(filepath, './' + _path().default.relative(_path().default.dirname(filepath), entry))))));
195
- } else {
196
- deps.set(importedPath, resolve(filepath, importedPath));
197
- }
198
- }
209
+ attemptResolve(importedPath, filepath, asset, resolve, deps);
199
210
  }
200
211
 
201
212
  }
@@ -247,10 +258,10 @@ async function getDependencies(code, filepath, asset, resolve, options, parcelOp
247
258
 
248
259
  for (let resolved of found) {
249
260
  if (!seen.has(resolved)) {
250
- await asset.addIncludedFile(resolved);
261
+ await asset.invalidateOnFileChange(resolved);
251
262
  let code = await asset.fs.readFile(resolved, 'utf8');
252
263
 
253
- for (let [path, resolvedPath] of await getDependencies(code, resolved, asset, resolve, options, parcelOptions, nativeGlob, seen)) {
264
+ for (let [path, resolvedPath] of await getDependencies(code, resolved, asset, resolve, options, parcelOptions, nativeGlob, seen, false)) {
254
265
  res.set(path, resolvedPath);
255
266
  }
256
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/transformer-stylus",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-nightly.1004+47379bf8",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,12 +17,12 @@
17
17
  "source": "src/StylusTransformer.js",
18
18
  "engines": {
19
19
  "node": ">= 12.0.0",
20
- "parcel": "^2.0.0-beta.1"
20
+ "parcel": "2.0.0-nightly.1002+47379bf8"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/plugin": "2.0.0-beta.2",
24
- "@parcel/utils": "2.0.0-beta.2",
25
- "stylus": "^0.54.5"
23
+ "@parcel/plugin": "2.0.0-nightly.1004+47379bf8",
24
+ "@parcel/utils": "2.0.0-nightly.1004+47379bf8",
25
+ "stylus": "^0.55.0"
26
26
  },
27
- "gitHead": "a3aa86815e098c90fda72a08d29646ff059ab74d"
27
+ "gitHead": "47379bf8fabeb2cfe03ade8802d942388b153e5b"
28
28
  }
@@ -22,7 +22,7 @@ export default (new Transformer({
22
22
  if (configFile) {
23
23
  let isJavascript = path.extname(configFile.filePath) === '.js';
24
24
  if (isJavascript) {
25
- config.shouldInvalidateOnStartup();
25
+ config.invalidateOnStartup();
26
26
  }
27
27
 
28
28
  // Resolve relative paths from config file
@@ -32,7 +32,7 @@ export default (new Transformer({
32
32
  );
33
33
  }
34
34
 
35
- config.setResult(configFile.contents);
35
+ return configFile.contents;
36
36
  }
37
37
  },
38
38
 
@@ -78,6 +78,36 @@ export default (new Transformer({
78
78
  },
79
79
  }): Transformer);
80
80
 
81
+ function attemptResolve(importedPath, filepath, asset, resolve, deps) {
82
+ if (deps.has(importedPath)) {
83
+ return;
84
+ }
85
+
86
+ if (isGlob(importedPath)) {
87
+ // Invalidate when new files are created that match the glob pattern.
88
+ let absoluteGlob = path.resolve(path.dirname(filepath), importedPath);
89
+ asset.invalidateOnFileCreate({glob: absoluteGlob});
90
+
91
+ deps.set(
92
+ importedPath,
93
+ glob(absoluteGlob, asset.fs, {
94
+ onlyFiles: true,
95
+ }).then(entries =>
96
+ Promise.all(
97
+ entries.map(entry =>
98
+ resolve(
99
+ filepath,
100
+ './' + path.relative(path.dirname(filepath), entry),
101
+ ),
102
+ ),
103
+ ),
104
+ ),
105
+ );
106
+ } else {
107
+ deps.set(importedPath, resolve(filepath, importedPath));
108
+ }
109
+ }
110
+
81
111
  async function getDependencies(
82
112
  code,
83
113
  filepath,
@@ -87,6 +117,7 @@ async function getDependencies(
87
117
  parcelOptions,
88
118
  nativeGlob,
89
119
  seen = new Set(),
120
+ includeImports = true,
90
121
  ) {
91
122
  seen.add(filepath);
92
123
 
@@ -96,35 +127,16 @@ async function getDependencies(
96
127
  let ast = parser.parse();
97
128
  let deps = new Map();
98
129
 
130
+ if (includeImports && options.imports) {
131
+ for (let importedPath of options.imports) {
132
+ attemptResolve(importedPath, filepath, asset, resolve, deps);
133
+ }
134
+ }
135
+
99
136
  class ImportVisitor extends DepsResolver {
100
137
  visitImport(imported) {
101
138
  let importedPath = imported.path.first.string;
102
-
103
- if (!deps.has(importedPath)) {
104
- if (isGlob(importedPath)) {
105
- // Invalidate when new files are created that match the glob pattern.
106
- let absoluteGlob = path.resolve(path.dirname(filepath), importedPath);
107
- asset.invalidateOnFileCreate({glob: absoluteGlob});
108
-
109
- deps.set(
110
- importedPath,
111
- glob(absoluteGlob, asset.fs, {
112
- onlyFiles: true,
113
- }).then(entries =>
114
- Promise.all(
115
- entries.map(entry =>
116
- resolve(
117
- filepath,
118
- './' + path.relative(path.dirname(filepath), entry),
119
- ),
120
- ),
121
- ),
122
- ),
123
- );
124
- } else {
125
- deps.set(importedPath, resolve(filepath, importedPath));
126
- }
127
- }
139
+ attemptResolve(importedPath, filepath, asset, resolve, deps);
128
140
  }
129
141
  }
130
142
 
@@ -180,7 +192,7 @@ async function getDependencies(
180
192
  // Recursively process resolved files as well to get nested deps
181
193
  for (let resolved of found) {
182
194
  if (!seen.has(resolved)) {
183
- await asset.addIncludedFile(resolved);
195
+ await asset.invalidateOnFileChange(resolved);
184
196
 
185
197
  let code = await asset.fs.readFile(resolved, 'utf8');
186
198
  for (let [path, resolvedPath] of await getDependencies(
@@ -192,6 +204,7 @@ async function getDependencies(
192
204
  parcelOptions,
193
205
  nativeGlob,
194
206
  seen,
207
+ false,
195
208
  )) {
196
209
  res.set(path, resolvedPath);
197
210
  }