Skip to content

Commit

Permalink
Merge branch 'v2' into bump-swc
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed May 10, 2024
2 parents 3c82330 + ef63bff commit 795716b
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::rc::Rc;
use napi::Env;
use napi::JsObject;
use napi_derive::napi;

use parcel_core::requests::config_request::run_config_request;
use parcel_core::requests::config_request::ConfigRequest;
use parcel_core::requests::request_api::js_request_api::JSRequestApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::rc::Rc;
use napi::Env;
use napi::JsObject;
use napi_derive::napi;

use parcel_core::requests::entry_request::run_entry_request;
use parcel_core::requests::entry_request::EntryRequestInput;
use parcel_core::requests::entry_request::EntryResult;
Expand Down
6 changes: 6 additions & 0 deletions crates/node-bindings/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ impl Resolver {
"esm" => SpecifierType::Esm,
"commonjs" => SpecifierType::Cjs,
"url" => SpecifierType::Url,
"custom" => {
return Err(napi::Error::new(
napi::Status::InvalidArg,
"Unsupported specifier type: custom",
))
}
_ => {
return Err(napi::Error::new(
napi::Status::InvalidArg,
Expand Down
3 changes: 2 additions & 1 deletion crates/parcel_core/src/requests/entry_request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ pub fn run_entry_request(

#[cfg(test)]
mod test {
use super::*;
use parcel_filesystem::in_memory_file_system::InMemoryFileSystem;

use super::*;

#[test]
fn test_merge_results() {
let entry1 = Entry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl FileSystem for JSDelegateFileSystem {
let result = call_method(
&self.env,
&self.js_delegate,
"canonicalize",
"realpathSync",
&[&js_path.into_unknown()],
)?;
Ok(path_from_js(result)?)
Expand Down
20 changes: 20 additions & 0 deletions crates/parcel_napi_helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use napi::bindgen_prelude::FromNapiValue;
use napi::Env;
use napi::JsFunction;
use napi::JsObject;
use napi::JsUndefined;
use napi::JsUnknown;
use napi::NapiRaw;

Expand Down Expand Up @@ -66,3 +67,22 @@ pub fn call_method(
let result = method_fn.call(Some(&js_object), &args)?;
Ok(result)
}

/// Logs napi values using the JavaScript console
///
/// This function can be used to debug what data the pointers actually refer to
///
pub fn console_log<T>(env: Env, args: &[T]) -> napi::Result<JsUndefined>
where
T: NapiRaw,
{
let console_object = env
.get_global()?
.get_named_property::<JsObject>("console")?;

console_object
.get_named_property_unchecked::<JsFunction>("log")?
.call(Some(&console_object), args)?;

env.get_undefined()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"version": "0.1",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
"service_worker": "background.js",
"type": "module",
"scripts": [ "background.js" ]
},
"permissions": [
"scripting",
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/webextension.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('webextension', function () {
assets: ['manifest.json'],
},
{assets: ['background.js']},
{assets: ['background.js']},
{assets: ['popup.html']},
{assets: ['popup.css']},
{assets: ['popup.js', 'esmodule-helpers.js', 'bundle-url.js']},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ async function collectDependencies(
...getJSONSourceLocation(ptrs['/background/page'], 'value'),
},
});
} else if (program.background?.service_worker) {
}
if (program.background?.service_worker) {
program.background.service_worker = asset.addURLDependency(
program.background.service_worker,
{
Expand Down
4 changes: 4 additions & 0 deletions packages/transformers/webextension/src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ export const MV3Schema = ({
type: 'string',
enum: ['classic', 'module'],
},
// to support both Chrome and Firefox
scripts: arrStr,
page: string,
persistent: boolean,
},
additionalProperties: false,
required: ['service_worker'],
Expand Down

0 comments on commit 795716b

Please sign in to comment.