Skip to content

Commit

Permalink
remove the dependency on package:web
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew committed Dec 20, 2024
1 parent c23c221 commit 1bd522f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pkgs/intl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.20.2-wip
## 0.20.2
* Remove the dependency on `package:http`.
* Remove the dependency on `package:web`.

## 0.20.1
* Upgrade `package:web` dependency constraint to `1.1.0`, fixes issue
Expand Down
23 changes: 12 additions & 11 deletions pkgs/intl/lib/intl_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

/// This provides facilities for Internationalization that are only available
/// when running in the web browser. You should import only one of this or
/// intl_standalone.dart. Right now the only thing provided here is the
/// ability to find the default locale from the browser.
/// intl_standalone.dart. Right now the only thing provided here is the ability
/// to find the default locale from the browser.
library;

import 'package:web/web.dart';
import 'intl.dart';
import 'src/web.dart';

// TODO(alanknight): The need to do this by forcing the user to specially
// import a particular library is a horrible hack, only done because there
// seems to be no graceful way to do this at all. Either mirror access on
// dart2js or the ability to do spawnUri in the browser would be promising
// as ways to get rid of this requirement.
/// Find the system locale, accessed as window.navigator.language, and
/// set it as the default for internationalization operations in the
/// [Intl.systemLocale] variable.
// TODO(alanknight): The need to do this by forcing the user to specially import
// a particular library is a horrible hack, only done because there seems to be
// no graceful way to do this at all. Either mirror access on dart2js or the
// ability to do spawnUri in the browser would be promising as ways to get rid
// of this requirement.

/// Find the system locale, accessed as window.navigator.language, and set it as
/// the default for internationalization operations in the [Intl.systemLocale]
/// variable.
Future<String> findSystemLocale() {
Intl.systemLocale = Intl.canonicalizedLocale(window.navigator.language);
return Future.value(Intl.systemLocale);
Expand Down
1 change: 1 addition & 0 deletions pkgs/intl/lib/intl_standalone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
library;

import 'dart:io';

import 'intl.dart';

// TODO(alanknight): The need to do this by forcing the user to specially
Expand Down
1 change: 1 addition & 0 deletions pkgs/intl/lib/message_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
library;

import 'dart:collection';

import 'intl.dart';

/// **MessageFormat grammar:**
Expand Down
1 change: 1 addition & 0 deletions pkgs/intl/lib/src/file_data_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ library;
import 'dart:io';

import 'package:path/path.dart';

import 'intl_helpers.dart';

class FileDataReader implements LocaleDataReader {
Expand Down
3 changes: 1 addition & 2 deletions pkgs/intl/lib/src/http_request_data_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ library;
import 'dart:async';
import 'dart:js_interop';

import 'package:web/web.dart';

import 'intl_helpers.dart';
import 'web.dart';

class HttpRequestDataReader implements LocaleDataReader {
/// The base url from which we read the data.
Expand Down
1 change: 1 addition & 0 deletions pkgs/intl/lib/src/intl/number_format_parser.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:math';

import 'package:intl/number_symbols.dart';
Expand Down
1 change: 1 addition & 0 deletions pkgs/intl/lib/src/lazy_locale_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
library;

import 'dart:convert';

import 'intl_helpers.dart';

/// This implements the very basic map-type operations which are used
Expand Down
30 changes: 30 additions & 0 deletions pkgs/intl/lib/src/web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Note: the contents of this file have been inlined from package:web/web.dart.
// We may periodically want to re-sync this, and / or look there when necessary
// to expose additional API.

import 'dart:js_interop';

@JS()
external Window get window;

extension type Window._(JSObject _) implements JSObject {
external Navigator get navigator;

external JSPromise<Response> fetch(
JSAny /*RequestInfo*/ input, [
JSObject /*RequestInit*/ init,
]);
}

extension type Navigator._(JSObject _) implements JSObject {
external String get language;
}

extension type Response._(JSObject _) implements JSObject {
external int get status;
external JSPromise<JSString> text();
}
3 changes: 1 addition & 2 deletions pkgs/intl/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: intl
version: 0.20.2-wip
version: 0.20.2
description: >-
Contains code to deal with internationalized/localized messages, date and
number formatting and parsing, bi-directional text, and other
Expand All @@ -18,7 +18,6 @@ dependencies:
clock: ^1.1.0
meta: ^1.3.0
path: ^1.8.0
web: ^1.1.0

dev_dependencies:
benchmark_harness: ^2.2.0
Expand Down

0 comments on commit 1bd522f

Please sign in to comment.